Pattern for managing distributed transactions in microservices through a sequence of local transactions with compensating actions to handle failures.
The Saga pattern manages transactions spanning multiple microservices. Instead of a distributed ACID transaction (costly and fragile), a saga is a sequence of local transactions where each step has a compensating action in case of failure.
Each service listens to events and decides what to do:
Order created → Inventory reserved → Payment processed → Order confirmed
↓ (failure)
Inventory released ← Payment rejected
A central orchestrator coordinates the steps:
Orchestrator → Reserve inventory → Process payment → Confirm order
← Compensate if any step fails
| Aspect | Choreography | Orchestration |
|---|---|---|
| Coupling | Low | Medium |
| Visibility | Hard to trace | Clear flow |
| Complexity | Grows with services | Centralized |
In distributed systems, ACID transactions don't cross service boundaries. The saga pattern coordinates distributed transactions through a sequence of local transactions with compensations, maintaining eventual consistency without distributed locks.
Architectural style structuring an application as a collection of small, independent, deployable services, each with its own business logic and data.
Architectural pattern where components communicate through asynchronous events, enabling decoupled, scalable, and reactive systems.
Pattern separating read and write operations into distinct models, optimizing each independently for performance and scalability.
Pattern where application state is derived from an immutable sequence of events, providing complete audit trail and the ability to reconstruct state at any point in time.
Observability technique tracking requests across multiple services in distributed systems, enabling bottleneck identification and failure diagnosis.