Overview
In a distributed system, traditional ACID transactions are difficult to implement. A Saga is a sequence of local transactions. Each local transaction updates the database and publishes an event to trigger the next local transaction in the saga.
Types
- Choreography: Each service produces and listens to events without a central coordinator.
- Orchestration: A central 'Saga Coordinator' tells the participants which local transactions to execute.
Compensating Transactions
If one local transaction fails, the saga must execute a series of 'compensating transactions' to undo the changes made by the preceding transactions, ensuring eventual consistency.