Skip to main content
  1. References/
  2. Architecture Design Basics/
  3. Pattern Taxonomy/
  4. Reliability, Consistency & Synchronisation/

Saga Pattern

·· 238 words· 2 mins

🔴 P0 — the distributed transaction pattern for microservices; critical for Stripe payment flows

Problem #

2PC doesn’t scale across services. But business processes (order → payment → inventory → shipping) still need atomicity. How do you achieve “all or nothing” without distributed locks?

Mechanism #

A saga is a sequence of local transactions, each with a compensating transaction that undoes its effect.

Forward:
  T1: Create Order         → success
  T2: Charge Payment       → success
  T3: Reserve Inventory    → FAILS

Compensate (reverse order):
  C2: Refund Payment
  C1: Cancel Order

Two Coordination Styles #

  • Choreography: Each service listens for events and triggers the next step (or compensation). Decentralised. See also: Choreography vs Orchestration.
  • Orchestration: A central saga coordinator drives the workflow, calling each service and handling compensations.

Key Trade-offs #

DimensionSaga2PC
AtomicityNo (compensating instead of rollback)Yes (true atomicity)
IsolationNo (intermediate states visible)Yes (locks held until commit)
AvailabilityHigh (no distributed locks)Lower (blocking protocol)
ComplexityCompensation logic per stepSimpler (commit/abort)
ScaleWorks across services/DCsLimited to few participants

Instinct #

Sagas are the standard for cross-service transactions in microservices.

The key design question is: “What does compensation look like for each step?”

For payments: compensation = refund.

For inventory: compensation = release reservation.

Always design compensation before the forward path. Orchestrated sagas are easier to reason about and debug for complex business processes.

References #

DDIA 2e Reference #

  • Chapter 9: Limitations of 2PC, saga as alternative
  • Chapter 12: End-to-end correctness