← Lessons

quiz vs the machine

Gold1470

System Design

The Saga for Distributed Payments

Chaining local commits with compensating actions to move money across services without locks.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. How does a saga undo work after a late failure?

2. What does a saga sacrifice compared to two phase commit?