When to reach for it
- Agents trigger external side effects.
- Distributed transactions are unavailable.
- Error reversal is technically feasible.
/pattern/saga-compensation/
A long-running transaction is split into steps, each paired with a compensating action; when a later step fails, the already-committed steps are undone in reverse order via their compensations, because a distributed transaction cannot hold a lock across all the resources at once.
In practiceA travel-booking agent books a flight, then a hotel; when the car-rental step fails, it automatically cancels the hotel and then the flight via their respective compensating actions.
When to reach for it
When it backfires
The tradeoff
More robust long-running processes are gained against complex compensation logic.
A failed step triggers compensating rollbacks.
The refund step fails. The system is now half-rolled-back: order cancelled, money still gone. Compensation is treated as if it cannot itself error.
Fix · Treat each compensation as a workflow with its own retries and dead-letter. Persist intent before attempting compensation so a recovery process can drive it to completion.
One step has no possible undo — an email sent, a payment settled, a message posted. A later failure cannot roll it back, so the saga cannot restore a consistent state.
Fix · Order irreversible steps last (the pivot), so everything before them is compensatable and everything after is retriable; gate a genuinely irreversible mid-flow action behind a human approval.
Keep going
Search patterns, frameworks, and pages.