Skip to main content

Posts

Showing posts from December, 2022

Distributed Transaction Management in Micro-services - SAGA Pattern

SAGA Pattern Maintains using a sequence of local transactions A local transaction updates the database and publishes an event to trigger the next local transaction in sequence. If any local transaction fails, then saga triggers a series of rollback transactions to undo the changes done by preceding local transactions and restores consistency. Uses PUB/SUB (Message Broker) Pattern or API Composition pattern for orchestration of events. Two ways of Implementing the SAGA Pattern a. Choreography Pattern 'Coordinate SAGA events using message brokers Each service publishes and subscribes to message broker If a service completes its work or completes the local transaction, it publishes the event in the message broker. Next microservice reads that event and starts its own local transaction and so on. If a transaction fails, then the same way the failing microservice publishes the rollback event, and the preceding microservice will start the rollback and so on. This way is good for a small