Saga Pattern Vocabulary
5 exercises — master distributed transaction vocabulary: saga pattern, compensating transactions, choreography vs orchestration, saga state persistence, and temporal coupling in event chains.
0 / 5 completed
Saga pattern vocabulary quick reference
- Saga — a sequence of local transactions with compensating transactions for rollback
- Compensating transaction — a new business operation that semantically reverses a prior step
- Choreography saga — services react to events independently; no central coordinator
- Orchestration saga — a central orchestrator directs each step via commands
- Outbox Pattern — ensures atomic state update + message publishing (crash-safe)
- Temporal coupling — saga progress depends on speed/availability of every service in the chain
- Saga timeout — maximum wait time per step before triggering compensation
1 / 5
What problem does the Saga pattern solve in microservices architectures?
The saga pattern exists because you cannot use a 2-phase commit (2PC) across microservices.
The problem sagas solve:
In a monolith, you can wrap a complex operation in a single database transaction — if any step fails, the whole thing rolls back atomically.
In microservices, each service owns its own database (Database Per Service pattern). You cannot create a single ACID transaction spanning multiple services. If an order creation involves the Order service, Payment service, and Inventory service — how do you ensure all succeed or all roll back?
The saga solution:
Break the distributed transaction into a sequence of local transactions, each in its own service. If a later step fails, execute compensating transactions in reverse order to undo the prior steps.
Example — Order creation saga:
①
②
③
④
If step ③ fails (out of stock):
←
←
←
Key vocabulary:
• Saga — a sequence of local transactions that together accomplish a distributed operation
• Compensating transaction — an action that semantically undoes a prior completed step
• Distributed transaction — a transaction spanning multiple services or databases
The problem sagas solve:
In a monolith, you can wrap a complex operation in a single database transaction — if any step fails, the whole thing rolls back atomically.
In microservices, each service owns its own database (Database Per Service pattern). You cannot create a single ACID transaction spanning multiple services. If an order creation involves the Order service, Payment service, and Inventory service — how do you ensure all succeed or all roll back?
The saga solution:
Break the distributed transaction into a sequence of local transactions, each in its own service. If a later step fails, execute compensating transactions in reverse order to undo the prior steps.
Example — Order creation saga:
①
OrderService: Create order (local tx) → emit OrderCreated②
PaymentService: Charge card (local tx) → emit PaymentCharged③
InventoryService: Reserve items (local tx) → emit ItemsReserved④
ShippingService: Schedule deliveryIf step ③ fails (out of stock):
←
InventoryService: Emit ItemsReservationFailed←
PaymentService: Refund card (compensating transaction)←
OrderService: Cancel order (compensating transaction)Key vocabulary:
• Saga — a sequence of local transactions that together accomplish a distributed operation
• Compensating transaction — an action that semantically undoes a prior completed step
• Distributed transaction — a transaction spanning multiple services or databases