SAGA Pattern Compensations
Maintain eventual consistency across microservices with compensating transactions instead of 2PC.

Abstract Algorithms
Quick Take
In distributed systems, committing transactions across multiple database nodes with Two-Phase Commit (2PC) blocks resources and limits scale. The SAGA pattern solves this by executing a series of loca
In distributed systems, committing transactions across multiple database nodes with Two-Phase Commit (2PC) blocks resources and limits scale. The SAGA pattern solves this by executing a series of local transactions.
If a transaction fails, SAGA triggers a sequence of compensating transactions to roll back updates in reverse order.
π SAGA Failure and Compensation
Normal Flow:
[ Create Order ] βββΊ [ Authorize Payment ] βββΊ [ Reserve Inventory ] (Failed!)
β
βΌ
Compensating Flow (Rollback): β
[ Cancel Order ] βββ [ Refund Payment ] βββββββββββββ
- Orchestration: A central orchestrator service coordinates the steps and commands.
- Choreography: Each service publishes events, and other services react, triggering the next step without a central manager.
AI-generated article quiz
Test your understanding
Ready to test what you just learned?
Generate four focused questions from this article. Answers include immediate explanations.
Reader feedback
Was this article useful?
Rate it if it helped, then continue with the next deep dive when you are ready.
Sign in to save your rating.