A refund nobody asked for
The treasurer of a youth football club orders 40 shirts with names and numbers from an online kit shop and pays €760. Ten minutes later her banking app shows the €760 charge and, under it, a €760 refund. The shop's logs tell the story in four lines:
- Inventory reserves 40 blank shirts in the club's sizes and commits.
- Payments charges the club's card €760 and commits.
- The print partner rejects the job: the crest file is 72 dpi, below its minimum.
- Payments refunds the €760, then Inventory puts the 40 shirts back on the shelf.
The last line is not a bug. It is the design doing its job, and the design has a name: a Saga.
Three systems, no shared commit
Inventory and Payments are separate services with their own databases, and the print partner is another company with an API. Were the reservation, the charge and the print job all rows in one database, one transaction could roll all three back when the print step failed. Across services, a single ACID transaction is impractical or unavailable. Two-phase commit explains the protocol that commits across databases and why services rarely use it: participants hold locks while they wait for the coordinator, and a card processor's API usually cannot take part at all.
A saga gives up on one commit. It runs the work as a sequence of local transactions, each committed by one service in its own database, each one triggering the next. If a step fails, the saga does not roll anything back, because there is nothing left to roll back: the earlier steps are already committed. Instead it runs a compensating transaction for each step that committed, in reverse order. The idea comes from a 1987 paper by Hector Garcia-Molina and Kenneth Salem on long-running transactions inside one database; services adopted it because it asks a participant for nothing but a local commit and an undo.
The card is declined, so only the reservation committed and only the reservation is compensated. Had the print step failed instead, the refund would run first, then the release.
An undo is a new transaction
The refund did not erase the charge; the treasurer saw both, and the card processor may keep its fee. A compensation semantically undoes a step: it is a new business operation that cancels the effect of an old one, not a rollback that pretends it never happened. Designing each undo is the job of the Compensating Action; the saga's part is choosing which ones run. A good run compensates exactly the steps that already committed, in reverse order, most recent first, so nothing is undone while a later step that built on it still stands.
Compensations must be idempotent, because they may be retried: Payments might crash after issuing the refund and before recording it, and the saga will ask again. A compensation can also fail outright, and the saga cannot give up on it, since a charge with no shirts behind it is exactly the state it exists to prevent. So it retries, and a compensation that can never succeed, such as a refund the card processor keeps rejecting, ends with a person. Retrying across a crash means the saga's progress is stored durably, in tables you keep or in an engine of the kind Durable workflows: orchestration that survives restarts describes.
The step you cannot take back
Now suppose the crest file passes and the partner prints SILVA 9 on a shirt. There is no compensation for that: the shirt cannot go back to the shelf as a blank. Printing is the saga's pivot, its point of no return. The steps before it must each have a compensation. The steps after it, booking the courier and sending the confirmation, have none; they must be idempotent steps that can be retried until they succeed. If the courier's API is down after the shirts are printed, the saga retries the booking with the backoff of a Retry policy, rather than refunding a club for shirts that already carry its players' names.
This makes the order of the steps a design decision. Compensatable steps go first, the pivot comes as late as it can, and only retriable steps follow it. The charge comes before the printing because nobody prints for an unpaid order. The common mistake is a forward step that a later failure can strand with no compensation: without a release, the opening's failed print job would have left 40 shirts reserved forever. Steps after the pivot need none, because from there the saga only moves forward.
Everyone else sees the half-finished order
For those ten minutes, the club's 40 shirts were reserved, the shop's last mediums among them. Another club that wanted 30 mediums was told they were out of stock and bought elsewhere, turned away by an order that never completed. A transaction in one database would have hidden the reservation until it committed. A saga cannot: each local step is visible the moment it commits. In the end everything should either complete or be compensated, but in between the saga has none of the isolation that Transactions & isolation levels describes inside one database: other requests read and act on intermediate state, and the design has to make up for it.
The damage can be worse than a lost sale. Say the release is written as "set stock back to 300", the value before the reservation. If 12 shirts were sold in between, the compensation shows 300 on the shelf when only 288 are left. Some common countermeasures:
- Commutative updates. Write the release as "add the 40 shirts back", which gives the same result whatever sales ran in between.
- Semantic lock. Mark the reservation
pendinguntil the saga ends. Other requests see the flag and decide: a second order that needs the same shirts can wait or fail fast. Something must clear the flag even after a crash. - Reordering the steps. Run the step most likely to fail first. Validating the crest file before reserving or charging would have spared the treasurer the refund and the other club the stock-out.
Who drives the steps
In an orchestrated saga, a coordinator sends Reserve, Charge and Print as commands and runs the compensations when a reply reports a failure, so the whole failure path sits in one place; that coordinator is usually built as a Process Manager. A choreographed saga has no coordinator: Payments refunds when it sees PrintRejected on the Event Bus, and Inventory releases when it sees the refund. Every service must know which failures concern it, which stays manageable for two or three steps and gets hard to follow beyond that, the trade-off at the heart of Choreography.
When a saga is the wrong answer
If every step is a write in one database, use a transaction; a call to an outside system, such as the card charge, stays outside it even in a single service. If a rule must hold at every instant across services, such as never holding stock for an order that is not paid, a saga cannot keep it, because its intermediate states are visible by design; that usually means the data belongs inside one service. And if a step can neither be compensated nor retried until it succeeds, no ordering makes the saga safe.
Break it at every step
Open the Saga challenge and model a saga coordinating the steps, each step a local transaction that emits an event, and a Compensating Action for each step that could be stranded. Then fail each step in turn and check which compensations fire: exactly the steps that already committed, in reverse order, and none once the pivot is behind you. Make it clear why no two-phase commit is involved. Saga Compensation Flow draws the same logic as a flowchart, with the reverse order made explicit.