Workflows
Sagas & compensating actions
Multi-step side effects without distributed transactions: each step has an undo.
What it is and why it exists
If an agent books a flight, a hotel and a car and the car fails, you can’t roll back a database transaction across three providers. A saga runs steps in order and, on failure, runs compensating actions (cancel hotel, cancel flight) in reverse.
Quick prototype
Hope the last step never fails.
In production, at scale
Each side-effecting tool paired with a compensation, executed by a durable workflow, with idempotency on both directions and a human queue for compensations that fail.
Vendors and tools
| Temporal saga pattern | Compensation in workflow code |
|---|---|
| Step Functions Catch → compensate | Saga state machines |
On AWS: Step Functions saga pattern with Catch blocks.
How it fails
- Compensation that itself isn’t idempotent
- Steps with no possible undo (an email) placed first
What the interviewer asks next
How would you order steps in a saga?
Reversible and cheap steps first, irreversible ones (send confirmation, charge) last, once everything else has succeeded.