When a business operation spans multiple microservices, each service performs its own local database transaction. If one service fails after others have already committed their changes, we cannot simply roll back the entire operation using a traditional database transaction.
Consider an e-commerce application where placing an order involves three services:
What happens if the inventory is reserved successfully, but the payment fails? The system needs to release the reserved inventory and cancel the order. It must also handle network failures, duplicate requests, and services that become temporarily unavailable.
The Saga Pattern provides a way to coordinate these multi-service business operations without relying on a single distributed database transaction. There are two primary ways to implement sagas: Choreography and Orchestration. Let's understand how both approaches work, their trade-offs, and when to choose each one.