The Saga Pattern: Choreography vs Orchestration
Manage distributed business transactions across microservices using compensating transactions, choreography, and centralized orchestrators.
01.1. What is the Saga Pattern?
Originally formulated by Hector Garcia-Molina and Kenneth Salem in 1987, a Saga is a sequence of independent local transactions that spans multiple microservices to accomplish a long-lived distributed business workflow.
Unlike Two-Phase Commit (which holds locks across services until the entire distributed transaction completes), each local transaction in a Saga:
- Executes locally against its own private database.
- Commits its changes immediately in milliseconds.
- Publishes a domain event or message to trigger the next step in the workflow.
The Compensating Transaction Mechanism:
If any step in the workflow fails (e.g., inventory is out of stock, or fraud detection flags the account), the Saga cannot execute a traditional database ROLLBACK because preceding steps have already committed.
Instead, the Saga executes a series of Compensating Transactions (C_1, C_2, \dots, C_k) in reverse order that semantically undo the side effects of committed steps (e.g., issuing a credit card refund, un-reserving warehouse stock, sending an apology email).
Saga Compensating Rollback Flow ⏪
Saga Compensating Rollback Flow ⏪
Failure at step 3 triggers backward compensating transactions across services.
Unlock Topic #88: The Saga Pattern: Choreography vs Orchestration
You are viewing a preview. The full in-depth engineering deep dive, interactive simulators, architecture flowcharts, and self-assessment quizzes for this topic are available with Pro or Lifetime Access.
Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.
Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.
Staff-level multiple-choice quiz questions with instant feedback and answer explanations.
Firebase Google authentication automatically syncs your completed topics and quiz scores.
How clear and staff-actionable was this system breakdown?