Saga Compensation Flow
A multi-service transaction as forward steps each paired with an undo, showing where the sequence becomes irreversible.
flowchart TB
subgraph fwd["Forward path"]
direction LR
f1["1. Reserve stock"] --> f2["2. Authorise payment"] --> f3["3. Create consignment"] --> f4["4. Capture payment"] --> f5["5. Despatch"]
end
subgraph comp["Compensation"]
direction RL
k1["Release stock"] --- k2["Void authorisation"] --- k3["Cancel consignment"] --- k4["Refund<br/><i>visible to customer</i>"]
end
f1 -.->|"undo"| k1
f2 -.->|"undo"| k2
f3 -.->|"undo"| k3
f4 -.->|"undo"| k4
f5 -.->|"no undo — goods have left"| x(["point of no return"])What it is
A distributed transaction expressed as a forward sequence where each step has a named compensating action. It replaces atomicity with semantic undo, and the design work is in three places: what each undo actually is, whether it is customer-visible, and where the point of no return sits.
Note that compensation is not rollback. Voiding an authorisation leaves no trace; a refund appears on a statement and generates a support call. Those are different costs and the diagram should say so.
When you produce it
For any business transaction spanning services or providers where two-phase commit is not available — which is nearly all of them. Especially where money and physical goods are both involved.
Who reads it
Engineers implementing each step and each undo. Product and operations, who must agree that a refund is an acceptable substitute for never having charged. Support, who will field the consequences.
What good looks like
- Irreversible steps are ordered last, and the point of no return is drawn.
- Every compensation is named and its customer visibility noted.
- Steps and compensations are both idempotent, and the diagram says so.
- The failure of a compensation is addressed — usually a dead-letter queue and a human, which is a legitimate answer as long as it is a chosen one.
Common mistakes
- Assuming every step can be undone. An email sent, a file delivered to a partner, a pallet on a lorry — these are facts about the world.
- Irreversible steps early, which forces expensive compensation for a routine failure.
- No plan for a failed compensation, which is exactly the case that produces a stuck record and a manual data fix.