Saga Pattern
Subject: Computer and Technology noun /ˈsɑː.ɡə ˈpæt.ərn/ 1 definition
- distributed-systems
- software-architecture
- design-patterns
- transaction-management
-
Definition (noun)
Entry #245 · UpdatedThe Saga Pattern is an architectural design pattern for maintaining eventual data consistency across multiple services in a distributed system without relying on distributed locks or two-phase commit protocols. Instead of wrapping an entire business workflow in a single atomic transaction, it decomposes the operation into a sequence of independent local transactions, each updating one service's database and triggering the next step via messages or events. If a step fails, the saga executes compensating transactions in reverse order to semantically undo preceding changes, trading strict isolation for higher availability and service autonomy.
Common Forms
Choreography-Based Saga: Coordinates workflows without a central controller by having each service publish domain events after completing a local transaction, keeping services loosely coupled for simple flows.
Orchestration-Based Saga: Uses a dedicated coordinator service to send explicit commands, track workflow state, and trigger compensating actions, simplifying complex branching and error handling.
Hybrid Saga: Combines centralized orchestration for core workflow steps and failure recovery with event-driven choreography for downstream notifications or independent side effects.
Example
In an e-commerce checkout flow, an Order Orchestrator creates a pending order in the Order Service, reserves stock in the Inventory Service, and requests payment authorization from the Payment Service. When the payment is declined, the saga triggers compensating actions in reverse order—releasing the reserved stock and canceling the pending order—to restore cross-service consistency without holding distributed locks.