What is a Saga?
A saga is a multi-step transaction with automatic rollback. If any step fails, all previously completed steps are undone via compensation actions.
The Problem
Multi-step operations can fail partway through:
Step 1: Reserve inventory ✓
Step 2: Charge payment ✓
Step 3: Ship order ✗ (fails!)
Result: Payment charged but order not shipped!
The Solution
Sagas automatically undo completed steps:
Step 1: Reserve inventory ✓
Step 2: Charge payment ✓
Step 3: Ship order ✗ (fails!)
Compensation:
Undo Step 2: Refund payment ✓
Undo Step 1: Release inventory ✓
Result: System back to original state
Key Properties
| Property | Description |
|---|---|
| Steps | Ordered list of actions |
| Compensations | Undo action for each step |
| Execution | Forward (step by step) |
| Rollback | Reverse (compensation by compensation) |
| Checkpoints | Resume from last successful step |