Saga pattern
medium 30 minA saga is a chain of local transactions, one per service, with an undo step for each.
Remember it
The few things worth knowing cold, and how to make them stick.
Memory hook
A chain of local transactions with an undo button for each step.
Booking a picnic in three places. If the boat is gone, cancel the basket, then the meadow.
Cheat sheet
- Consistency
- Eventual
- Coordination
- Orchestration or choreography
- Rollback
- Compensation, newest first
- State
- Saved before and after each step
- Isolation
- None; use a semantic lock
Spot it when you see
- One business action over several services
- Processes that last longer than a lock may
Tricks that stick
- SAGA: Sequence of local transactions; Apologise (compensate) on failure; Goes to a consistent end; Autonomous services.
- T1, T2, T3 fails, C2, C1: forward, then backward.
Do not forget
- Compensations that are swallowed when they fail
- State kept only in memory
- Treating a timeout as a failure without effect