A teammate says a saga can just roll everything back if step four fails. What is wrong with that, and what would you tell them to build instead?
A saga has no rollback. Each step already committed in its own database and was visible to everyone, so you can only run new forward transactions that semantically offset it. Compensations are not atomic, some actions cannot be compensated at all, and compensations themselves fail - so a saga needs idempotent handlers and an ordering rule for irreversible steps.
Answer
Short answer
A saga has no rollback, because there is nothing left to roll back. Each step committed in its own database and became visible to every other service the moment it did. What a saga offers instead is compensation: new forward transactions that semantically offset earlier ones. Compensation is not atomic, some actions cannot be compensated at all, and the compensating transaction can itself fail — which is why "just roll it back" is not a design.
Was this answer helpful?
Likely follow-ups
- Step four fails and its compensation also fails after all retries. What happens next?
- Which of your steps are irreversible, and how does that change the order you run them in?
- A customer reads their order status midway through the saga and sees a state that never legally existed. How do you handle that?
- When would you choose orchestration over choreography for this, and what does that cost you?
- Would two-phase commit have solved this? Why is it usually not on the table?
Related questions
- How do you decide where one service ends and the next begins, and when is a modular monolith the more honest answer?hardAlso on microservices and saga7 min
- Two teams own two services that talk to each other. How do you stop one breaking the other without running both together in a shared environment?mediumAlso on microservices4 min
- Two users edit the same record while offline and both reconnect. How do you reconcile the two versions without silently losing one of the edits?hardAlso on eventual-consistency6 min
- Walk me through what happens between a customer order being captured and the service being live on the network.hardAlso on saga5 min