What a saga is
A saga splits a cross service payment into a sequence of local transactions, one per service. Each step commits immediately. If a later step fails, the saga runs a compensating transaction to undo each completed step.
Unlike two phase commit, a saga holds no cross service locks, so it stays available when a participant is slow.
A payment example
- Reserve funds in the wallet.
- Record a charge in the ledger.
- Notify the merchant.
If the merchant step fails, the saga compensates by reversing the ledger charge and releasing the wallet reservation.
Design notes
- Each step and its compensation must be idempotent because retries happen.
- Compensations run in reverse order of the completed steps.
- A saga gives atomicity at the business level, not isolation, so other readers may see intermediate states.
Key idea
A saga moves money across services as a chain of local commits, undoing completed steps with compensations when a later step fails, trading isolation for availability.