🏗️Saga Pattern
Also known as Saga, Distributed Transaction, Compensating Transaction
Split a task across services into steps. Each step has its own undo.
Think of it like
Think of it like booking a trip step by step. If the hotel is full, you cancel the flight you booked.
Example
Lucy's travel site books a flight, then a hotel, then a car. The car step fails, so the saga cancels the hotel and then the flight, and the customer is not charged.
Why it matters
In microservices there is no single transaction to roll back. Sagas are how data stays right when one step fails.
Definition
Common mistake
Key takeaways
- 1Steps across services. Each does its part.
- 2Every step has an undo. A compensating action.
- 3Fail, then reverse. Undo in back order.