Saga
Description
A saga is a long-running transaction broken into a sequence of local sub-transactions, each independently committable, with explicit compensating actions for each. If sub-step N fails, the saga runs compensations for steps N-1, N-2, …, 1 in reverse order, semantically rolling back the partially-applied work. The structural payoff is “atomic-feeling” multi-step operations across systems that can’t share a transaction boundary — microservices, multi-vendor bookings, multi-organization workflows. The diagnostic shape: a multi-step operation crosses transaction boundaries (multiple services, multiple databases, multiple external APIs), and you need “all-or-nothing” semantics but can’t get it via a single transaction. The saga replaces atomic-by-isolation with atomic-by-compensation. The compensations are not always exact inverses — you can refund a charge, but you can’t un-send an email — so the property is semantic reversal, not literal reversal. Two flavors: orchestration-based (a central coordinator drives the saga; explicit, debuggable, single point of failure for the coordinator) and choreography-based (each step publishes events; next step listens; no central coordinator, no single point of failure, but harder to reason about end-to-end).Triggers
User-initiated: User describes a multi-step operation across systems where atomicity is needed but 2PC isn’t available or desirable. Vocabulary cues: “saga,” “distributed transaction,” “long-running transaction,” “compensating transaction,” “rollback,” “workflow,” “orchestration.” Agent-initiated: Engine notices a multi-step operation crossing service boundaries with no obvious rollback story for partial failures. Candidate inference: “this is a saga — what are the forward steps, what are the compensations for each, and who’s the coordinator?” Situation-shape signals: Multi-step operation across services / databases / vendors; partial failure is observable to users; need all-or-nothing semantics but can’t get a single transaction boundary; 2PC is operationally untenable (microservices, external APIs).Exclusions
- Single-database operations — local ACID transactions are simpler and stronger; don’t introduce saga complexity if you don’t have to.
- No compensation possible — if a forward step is structurally irreversible (sent email, fired missile, public press release), the saga’s compensation story breaks. Use forward-only with explicit acceptance of partial-completion.
- Cross-step dependencies that violate compensation order — if compensating step 2 requires step 3’s state, the reverse-order rollback doesn’t work. Saga assumes per-step compensations are independent.
- High-frequency-low-latency operations — saga’s compensation machinery has real overhead; for high-throughput operations a different model (idempotent forward-only with eventual consistency) may dominate.
Structure
Relationships
- bookends — every forward step needs its compensation bookend.
- graceful-degradation — sagas are degradation applied to multi-step transactions.
- event-sourcing — choreography-based sagas need an event log to drive the choreography.
- idempotency — both forward steps and compensations must be safely retryable.
- load-bearing — the compensation chain is load-bearing for the saga’s correctness; missing compensations make the saga lossy.
Examples
Microservices order processing · computer-science
Microservices order processing · computer-science
Travel booking workflows · transportation
Travel booking workflows · transportation
AWS Step Functions and Temporal documentation — modern platform-level instantiations. · computer-science
AWS Step Functions and Temporal documentation — modern platform-level instantiations. · computer-science
CI/CD deployment pipelines · computer-science
CI/CD deployment pipelines · computer-science
Criminal investigation evidence chains · law
Criminal investigation evidence chains · law
E-commerce checkout · computer-science
E-commerce checkout · computer-science
Garcia-Molina & Salem, *Sagas* (SIGMOD 1987) — the original paper. · computer-science
Garcia-Molina & Salem, *Sagas* (SIGMOD 1987) — the original paper. · computer-science
Pat Helland, "Life beyond Distributed Transactions: an Apostate's Opinion," 3rd Biennial Conference on Innovative Data Systems Research (CIDR), 2007. · computer-science
Pat Helland, "Life beyond Distributed Transactions: an Apostate's Opinion," 3rd Biennial Conference on Innovative Data Systems Research (CIDR), 2007. · computer-science
Kleppmann, *Designing Data-Intensive Applications* (2017), Chapter 9 — modern framing. · computer-science
Kleppmann, *Designing Data-Intensive Applications* (2017), Chapter 9 — modern framing. · computer-science
Long-running scientific experiments · physics
Long-running scientific experiments · physics
Richardson, C., *Microservices Patterns* (2018) — the canonical microservices-architecture treatment. · computer-science
Richardson, C., *Microservices Patterns* (2018) — the canonical microservices-architecture treatment. · computer-science
Wedding planning · family-and-consumer-science
Wedding planning · family-and-consumer-science
workflow-engine literature (Temporal, AWS Step Functions, Airflow); microservices patterns (Newman, Building Microservices) · computer-science
workflow-engine literature (Temporal, AWS Step Functions, Airflow); microservices patterns (Newman, Building Microservices) · computer-science