SagaMicroservicesTransactions

SAGA Pattern Compensations

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

Abstract Algorithms

Abstract Algorithms

Jul 2, 2026Β·1 min readΒ·Intermediate
⚑

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.