← Concepts
Distributed Systems·3 min read

Saga Pattern (Distributed Transactions)

Replace a cross-service ACID transaction with a sequence of local transactions plus compensating actions to undo on failure.

First time reading this? Start here

Plain English: you can't run one database transaction across multiple microservices. A saga breaks a multi-step operation (reserve seat, charge card, send ticket) into separate local steps, and if a later step fails, it runs 'undo' actions (refund the card, release the seat) for the earlier ones. It's how you fake a transaction across services.

Used in:Ticketmaster (Seat Booking)Airbnb (Marketplace)Payment Gateway
What it is

A pattern for managing data consistency across multiple services without a distributed ACID transaction. A saga is a sequence of local transactions, each in a single service; each step has a corresponding compensating transaction that semantically undoes it. If any step fails, the saga executes the compensations for the already-completed steps in reverse, leaving the system in a consistent (rolled-back) state.

The problem it solves

Microservices each own their database, so a single business operation spanning several of them can't use one BEGIN/COMMIT, since there's no shared transaction. Two-phase commit across services exists but is slow, locks resources, and couples availability to every participant. Sagas provide consistency without distributed locks: each service commits locally and independently, and failure is handled by compensating actions rather than a global rollback.

How it works

Two coordination styles. Choreography: each service listens for events and emits the next one ('SeatReserved' → Payment service charges → 'PaymentFailed' triggers seat release). No central coordinator; simple for short flows, tangled for long ones. Orchestration: a central orchestrator explicitly tells each service what to do and what to compensate, tracking saga state. On failure at step N, the orchestrator (or the event chain) invokes compensating transactions for steps N-1…1 in reverse. Compensations must be idempotent and semantic ('refund' rather than literal rollback, since the original commit is permanent).

Why use it
What it costs you
Where it shows up in our architectures
Gotchas

Your notes

Private to you