Part 3: The Saga Pattern
Since we can't lock resources across services, we use the Saga Pattern. A Saga is a sequence of local transactions where each step has a Compensating Transaction to undo its work.
1. Two Architectures
- Choreography: Services talk to each other via events. Best for simple flows.
- Orchestration: A central state machine manages the flow. Best for complex business logic.
2. Handling Failure
If "Payment Service" fails, the Saga triggers a "Release Inventory" command to the "Inventory Service." This is Eventual Consistency in action.
