A saga has done three of five steps and step four fails. What happens next, and what if a compensation fails too?
Sketch your own answer first, then compare it with the one below.
A strong answer
The saga runs the compensations for steps three, two and one, in reverse order. When they finish, the saga ends as compensated.
A compensation that fails is retried. It must be safe to repeat, so give it an idempotency key. If it keeps failing, the saga cannot finish by itself. Park it, raise an alert, and let a person or a repair job decide. Compensations should be written so they cannot fail for business reasons, only for transient ones.
The orchestrator must write its progress durably before each step. After a crash, it reads where the saga stood and carries on.
Sources
- Hector Garcia-Molina, Kenneth Salem (1987). Sagas.
- Chris Richardson (2018). Pattern: Saga.