How to manage distributed transactions and data consistency in microservices without locking the world.
A Saga is a sequence of local transactions. Each local transaction updates the database and publishes a message or event to trigger the next local transaction in the saga.
If a local transaction fails because it violates a business rule, the saga executes compensating transactions that undo the changes that were made by the preceding local transactions.
In monolithic apps, we use ACID transactions (commit/rollback). In microservices, a single transaction can't span multiple databases easily. link Sagas provide a way to maintain data consistency across services without the performance hit of global locking (like 2PC).
Visualizing the shift from ACID to BASE consistency
See how a Saga handles success and failure. Watch the "Compensating Transactions" (Rollbacks) in action when a step fails.
A central coordinator (The "Conductor") tells participants what local transactions to execute.
Decentralized. Each service produces and listens to events, deciding action independently.