---
topic: system-design
author: Crashtech Editorial
published: Nov 15, 2026 · read: 6 min
---

Saga Pattern Demystified: Orchestration vs Choreography for Distributed Transactions and Compensating Actions

A comprehensive guide to the Saga pattern: Two-Phase Commit failure modes, compensating transactions, choreography vs orchestration, and idempotency.

– –

In a monolithic architecture, managing transactions across multiple business entities is simple. A relational database provides ACID guarantees (Atomicity, Consistency, Isolation, Durability) out of the box:

BEGIN TRANSACTION;
UPDATE inventory SET stock = stock - 1 WHERE item_id = 902;
INSERT INTO orders (user_id, status) VALUES (101, 'CONFIRMED');
INSERT INTO payments (amount, status) VALUES (45.00, 'PAID');
COMMIT; -- If any statement fails, the database rolls back atomically!

In a microservices architecture, this safety net vanishes. Following the Database-per-Service rule, the Order Service, Inventory Service, Payment Service, and Shipping Service each maintain completely independent, isolated databases.

When a customer checks out, an operation must span four disparate network boundaries. A standard database transaction cannot cross physical network cables and database instances without introducing fatal bottlenecks.

Historically, distributed systems attempted to solve this using Two-Phase Commit (2PC). In modern cloud environments, 2PC is widely recognized as an anti-pattern. Instead, distributed systems rely on the Saga Pattern: breaking a distributed transaction into a sequence of local transactions coordinated through forward execution and explicit compensating actions.

+-----------------------------------------------------------------------------------+
|               TWO-PHASE COMMIT (LOCKING) VS SAGA PATTERN (EVENTUAL)               |
+-----------------------------------------------------------------------------------+

[ Two-Phase Commit (2PC): Blocking Distributed Locks ]
Coordinator =====(Prepare Phase: Hold Locks)=====> [ Order DB ]  [ Inventory DB ]  [ Payment DB ]
Coordinator =====(Commit Phase: Release Locks)====> [ All nodes commit simultaneously ]
* If one node hangs or network drops, all database rows remain locked indefinitely!

[ The Saga Pattern: Sequence of Local ACID Transactions ]
Step 1: Order Service    ---> Local ACID Commit (Status: PENDING)
Step 2: Inventory Service---> Local ACID Commit (Stock Reserved)
Step 3: Payment Service  ---> Local ACID Commit (Payment Failed!)
Step 4: Compensation!    ---> Order Service: Cancel Order & Inventory Service: Release Stock

1. Why Two-Phase Commit (2PC / XA) Fails at Scale

Two-Phase Commit is mathematically sound in theory, but operationally fragile in practice:

  1. Synchronous Distributed Locking: During the Prepare phase, every participating database must acquire exclusive row locks. These locks remain held across network round trips until the coordinator issues the final Commit signal.
  2. Availability Collapse: The availability of a 2PC transaction is the mathematical product of all participants:
Availability_2PC = Availability_Coordinator * Availability_Service_A * Availability_Service_B * Availability_Service_C

If five services boast 99.9% uptime, the combined availability of a 2PC transaction drops to 99.5%, translating to over 43 hours of transaction failures annually. 3. Coordinator Crash Vulnerability: If the central 2PC coordinator crashes mid-transaction after participants have voted “Prepared”, all participating databases are left in an indefinite limbo state, holding locks and rejecting subsequent transactions.


2. Anatomy of a Saga: Local Transactions and Compensations

Formulated in 1987 by Hector Garcia-Molina and Kenneth Salem, a Saga is a design pattern that replaces distributed locks with an asynchronous chain of local transactions:

Saga = [T_1, T_2, T_3, ..., T_n]
  • Every local transaction T_i updates data in a single service and commits immediately within a local ACID transaction.
  • If all steps T_1 through T_n succeed, the Saga completes successfully.
  • If step T_k fails (e.g., payment declined or out of stock), the system must execute a sequence of Compensating Transactions in reverse order to undo prior mutations:
Rollback Sequence = [C_{k-1}, C_{k-2}, ..., C_1]
+-----------------------------------------------------------------------------------+
|                         FORWARD SUCCESS VS BACKWARD COMPENSATION                  |
+-----------------------------------------------------------------------------------+

[ Successful Happy Path ]
[ T1: Create Order ] ---> [ T2: Reserve Stock ] ---> [ T3: Process Payment ] ---> [ Complete ]

[ Failure at Step 3: Payment Declined ]
[ T1: Create Order ] ---> [ T2: Reserve Stock ] ---> [ T3: Payment Fails! ]
                                                           |
                                                           v
[ C1: Cancel Order ] <--- [ C2: Release Stock ] <----------+
(Rollback is achieved via active compensating updates, not database rollbacks)

The Difference Between Rollback and Compensation

In a single database, ROLLBACK physically erases uncommitted bytes from the write-ahead log as if the transaction never happened.

In a Saga, step T_1 already committed to the database. Its changes are visible to external users. A compensating transaction C_1 does not erase history: it applies an explicit semantic inverse update (e.g., issuing an INSERT INTO refunds or setting status = 'CANCELLED').


3. Implementation Pattern 1: Choreography (Event-Driven)

In a choreographed saga, there is no centralized controller. Participating microservices communicate asynchronously by publishing and listening to domain events over a message broker (such as Apache Kafka or RabbitMQ).

+-----------------------------------------------------------------------------------+
|                        CHOREOGRAPHED SAGA (EVENT-DRIVEN FLOW)                     |
+-----------------------------------------------------------------------------------+

[ User ]
   |
   v
[ Order Service ] --(Emits: OrderCreated)-------------------+
   |                                                        |
   |                                                        v
   |                                               [ Inventory Service ]
   |                                                  |-- Deducts Stock Locally
   |                                                  \--(Emits: StockReserved)-----+
   |                                                                                |
   |                                                                                v
   |                                               [ Payment Service ]
   |                                                  |-- Charges Card Locally
   |<-(Emits: PaymentCompleted)-----------------------+
   |
   v
[ Order Service ] -> Updates status: CONFIRMED

Advantages of Choreography:

  • Simplicity for Small Workflows: Simple to stand up when a workflow involves only 2 or 3 microservices.
  • Loose Coupling: Services publish domain events without knowing who consumes them.

Pitfalls of Choreography at Scale:

  • Pinball Machine Architecture: With 10+ services, understanding where an order is stuck becomes nearly impossible. Event paths bounce unpredictably across services.
  • Cyclic Dependency Hazards: Services often end up subscribing to each other’s events in circular loops, creating race conditions.
  • Difficult Error Handling: If step 5 fails, orchestrating the exact inverse sequence of compensating events across 4 different message topics is notoriously error-prone.

4. Implementation Pattern 2: Orchestration (Command-Driven)

In an orchestrated saga, a dedicated Saga Orchestrator (state machine) acts as the central conductor. The orchestrator explicitly sends command messages to services, awaits responses, and decides which step to execute next.

+-----------------------------------------------------------------------------------+
|                        ORCHESTRATED SAGA (STATE MACHINE FLOW)                     |
+-----------------------------------------------------------------------------------+

                              +----------------------------+
                              |     SAGA ORCHESTRATOR      |
                              |   (Order Checkout Saga)    |
                              +----------------------------+
                                |      ^      |      ^
            1. Command: Reserve |      |      |      | 3. Command: Charge
                  Inventory     |      |      |      |        Payment
                                v      |      v      |
                       [ Inventory Srv ]    [ Payment Srv ]
                               |               |
                         2. Reply: Ok    4. Reply: Failed
                                               |
                                               v
                              +----------------------------+
                              | ORCHESTRATOR COMPENSATES:  |
                              | 1. Command: Release Stock  |
                              | 2. Command: Set Cancelled  |
                              +----------------------------+

Modern Orchestrator Frameworks:

Rather than writing custom, bug-ridden database state machines, production teams utilize specialized workflow orchestration engines:

  • Temporal / Cadence: Open-source, code-first workflow engines that persist execution state, timers, and retries in durable code.
  • AWS Step Functions: Managed JSON/YAML state machine orchestrator integrating directly with serverless components.

Advantages of Orchestration:

  • Single Source of Truth: A visual state machine displays exactly which step an order is currently in, when it started, and its retry counts.
  • Straightforward Compensation: If an error occurs, the orchestrator executes the compensating loop systematically in reverse order.
  • Separation of Concerns: Participating services remain pure worker units; they execute commands and report status without embedding global business workflow logic.

5. Architectural Comparison: Choreography vs Orchestration

DimensionChoreographed SagaOrchestrated Saga
Coordination ModelDecentralized pub/sub eventsCentralized state machine commands
Optimal Workflow SizeSmall (2 to 4 service steps)Complex (5+ steps with branching paths)
System VisibilityPoor (Requires distributed tracing)Outstanding (Visual DAG dashboards)
Failure HandlingComplex reverse event choreographyDeterministic automated compensating loops
Coupling TypeLoosely coupled message topicsServices coupled to orchestrator contract
Single Point of FailureMessage brokerOrchestrator state store (mitigated via HA)

6. The Missing “I” in ACID: Surviving Lack of Isolation

The most critical challenge in Saga design is the absence of data isolation. Because each local transaction commits immediately, intermediate states are visible to concurrent users before the overall Saga completes.

Consider this race condition:

  1. Saga 1 reserves the last pair of sneakers in stock for User A (Step 2 committed).
  2. User B queries the product catalog: sneakers show “Out of Stock”.
  3. Saga 1 subsequently fails payment processing at Step 3.
  4. Saga 1 executes compensation, restocking the sneakers.
  5. In the meantime, User B navigated away because the item appeared unavailable.

Countermeasures for Isolation Anomalies:

  • Semantic Locking (Pending States): When a local transaction commits, it tags the record with a pending flag (e.g., ORDER_PENDING or PAYMENT_AUTHORIZING). Other workflows inspecting that record recognize that a Saga is in flight and apply defensive logic.
  • Commutative Updates: Design operations so that execution order does not alter the mathematical outcome. For example, balance adjustments (+50 or -50) are commutative, whereas setting absolute balances (balance = 200) is prone to lost updates.
  • Pessimistic Timeouts: Enforce explicit TTL expiration windows on reserved resources, automatically reverting held inventory if a confirmation signal is not received within 15 minutes.

Summary Takeaways

  • 2PC does not scale: Distributed two-phase locking degrades availability and exhausts database connections; adopt Sagas for distributed cross-service workflows.
  • Sagas trade isolation for availability: Break distributed operations into local ACID transactions, managing rollbacks through semantic compensating actions.
  • Use choreography for simple pipelines: Decentralized event reacting works cleanly for 2 to 3 microservice interactions.
  • Use orchestration for enterprise complexity: Deploy modern state machines (such as Temporal or Step Functions) when workflows require complex multi-step branching, human approvals, or transparent auditing.
  • Design all steps to be idempotent: Because message brokers guarantee at-least-once delivery, every forward action and compensating action must safely handle duplicate execution.
Advertisement

Frequently asked questions

Why is Two-Phase Commit (2PC) considered an anti-pattern in modern cloud microservices?

2PC requires a centralized coordinator to hold distributed lock leases across all participating databases simultaneously throughout a prepare and commit phase. If any network link falters or a participant stalls, database rows remain locked, exhausting connection pools and crippling system availability.

What is a compensating transaction in the Saga pattern?

A compensating transaction is an explicit business undo operation. Because Sagas commit local database transactions sequentially, rolling back a failed multi-step workflow cannot rely on standard database rollback. Instead, previously committed steps execute backward compensations (such as issuing a refund or releasing reserved inventory).

What are the primary trade-offs between Choreography and Orchestration in Sagas?

Choreography is decentralized: services react to event streams without a central coordinator, offering high autonomy for short workflows. However, complex choreographies create difficult-to-trace cyclic dependencies. Orchestration centralizes execution in a state machine, offering clear visibility and explicit error handling at the cost of coordinator coupling.

How do architects handle the lack of isolation (the 'I' in ACID) in Sagas?

Because intermediate Saga transactions commit to local databases immediately, other concurrent requests can observe uncommitted business states. Architects mitigate this by using semantic locking (flagging records as 'PENDING_APPROVAL'), commutative updates, and pessimistic reservation timeouts.

Sources & further reading

/* Comments */