Giter Site home page Giter Site logo

aenesgur / microservice-saga-outbox-inbox-pattern Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 167 KB

This repo contains Saga, Outbox, Inbox and Distributed Lock Patterns with a sample Spring Boot application.

Java 99.19% Dockerfile 0.81%
distributed-lock distributed-locking docker inbox-pattern kafka outbox-pattern postgresql redis saga-pattern spring-boot

microservice-saga-outbox-inbox-pattern's Introduction

Microservice Application with Saga, Outbox, Inbox, Distributed Locking Design Patterns

Microservice boilerplate application developed with Outbox/Inbox pattern and Distributed Locking

Technologies

  • Spring Boot
  • Spring Data
  • Apache Kafka
  • Redis
  • Docker
  • Postgresql

What is Inbox/Outbox pattern?

The Inbox-Outbox pattern is a messaging pattern used in distributed systems to improve the performance and reliability of communication between components.

In this pattern, each component has two message queues: an inbox and an outbox. The inbox receives messages from other components, while the outbox holds messages that the component needs to send to other components.

The component processes messages from its inbox in a separate thread, and once it completes processing a message, it places the response message in its outbox. The outbox messages are then sent by a separate thread that continuously polls the outbox queue for new messages and sends them to their destinations.

This pattern can help improve performance and reliability by decoupling the sending and receiving of messages, reducing contention and preventing message loss. It also enables components to operate asynchronously, allowing them to continue processing messages from their inbox while messages from their outbox are being sent.

What is Distributed Locking?

Distributed locking is a technique used in distributed computing systems to ensure that multiple processes or threads don't interfere with each other when accessing shared resources, such as data or files. The basic idea behind distributed locking is to use a shared lock that multiple processes or threads can acquire and release as needed.

Distributed locking is important in distributed systems because it helps prevent conflicts and inconsistencies that can arise when multiple processes or threads try to access the same shared resource simultaneously. By using a distributed lock, each process or thread can take turns accessing the shared resource in a coordinated and orderly way, which helps maintain system stability and reliability.

System Diagram

microservice-saga-outbox-inbox-pattern

Distributed Lock Diagram

distributed-lock

Run

First: mvn clean install

Then: docker compose up -d

Test

Test for payment-fail-topic:

curl --location --request POST 'localhost:4041/api/orders' \ --header 'Content-Type: application/json' \ --data-raw '{ "totalPrice": 12, "cardNo":"27411111222233334444", "userId": 45623, "orderNote":"lorem ipsum" }'

Test for payment-complete-topic:

curl --location --request POST 'localhost:4041/api/orders' \ --header 'Content-Type: application/json' \ --data-raw '{ "totalPrice": 12, "cardNo":"77411111222233334444", "userId": 45623, "orderNote":"lorem ipsum" }'

microservice-saga-outbox-inbox-pattern's People

Contributors

aenesgur avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

rainsunon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.