How it works · 26 of 49 Advanced

What is the saga pattern for distributed transactions?

A transaction across services, with undo steps

Sagas: One business action that spans several services (book a flight, a hotel and a car, then charge the card) cannot be one database transaction: each service commits to its own database. A saga runs it as a chain of local transactions, each committed on its own. If a step fails, the saga runs *compensating* transactions (undo steps) for the steps already done, in reverse order. One step is the *pivot*, the point of no return: before it every step can be undone; after it, steps are never undone, only retried until they succeed. The price: undo steps you must design and test, and no isolation, so others can see a half-finished trip.

Loading the animation…

Say it like this A saga runs one business action as a chain of local transactions across services, and when a step fails it runs an undo step for each finished step in reverse; past the pivot, steps are only retried, never undone.

Under the hood — for builders
The sources, in their words
Garcia-Molina and Salem ("Sagas", SIGMOD 1987), who named it: "either all the transactions in a saga are successfully completed or compensating transactions are run to amend a partial execution." Chris Richardson (microservices.io): "A saga is a reliably coordinated sequence of local transactions."
The card's trip, step by step
Local transaction: one service's commit to its own database. Compensating transaction: the undo step written for it. Pivot: the point of no return (Microsoft). Retryable: after the pivot, safe to repeat until it succeeds.
Run here: what a failed trip leaves behind
10,000 trips; steps fail at 2% (flight), 3% (hotel), 5% (car), 4% (payment); about 1,350 trips fail. Failed trips left with something booked:
Run here: a lost reply, a second refund
Same runs: 2% of refund replies are lost, so the caller sends the refund again. Refunds paid twice:
No isolation
Microsoft: others can see a half-done saga: "Lost updates", "Dirty reads", "Fuzzy, or nonrepeatable, reads". Fixes: a "Semantic lock" (mark the room pending), "Reread values".
Who coordinates
An orchestrator that sends each command, or services reacting to each other's events (C4). Microsoft: orchestration suits complex flows; choreography adds no extra service.
Measure it
Sagas stuck compensating · age of the oldest open saga · undo steps that failed · repeats rejected by idempotency key.
Watch out
Order steps so the hardest to undo comes last; a refund is a new payment, with its own fees and e-mails. Our run is a toy.
Sources
Garcia-Molina & Salem, "Sagas", SIGMOD 1987 · Chris Richardson, "Pattern: Saga", microservices.io · Microsoft, "Saga design pattern", Azure Architecture Center, 2025 · all read in session · trip simulation, Python, 19 Nov 2026.

What happens in the sagas animation, step by step?

  1. One trip, five services, five databases: flight, hotel, car, payment, tickets. No single transaction can span them.
  2. A saga books each step as its own local transaction. Each stop commits on its own, then sends the traveller on.
  3. Car hire has no cars. The flight and hotel are already committed in their own databases; nothing can roll them back.
  4. So the saga walks back, running an undo step at each stop in reverse: cancel the hotel, then the flight. Each hands over a refund.
  5. Your turn: tap any stop to make it fail, and watch what the saga undoes.
  6. Payment is the pivot: before it, undo; after it, retry until done. An undo is a new action, not an erasure. Next: fail for some customers, never for all.

What everyday example explains sagas?

Cancelling a trip: car, then hotel, then flight, each with its own phone call and its own refund.

Why should a team care about sagas?

"just roll it back" stops working the moment data lives in two services. Every checkout, booking and agent that acts in more than one system needs its undo steps written before the first failure, not after.