← Lessons

quiz vs the machine

Platinum1850

System Design

Order Saga Deep Dive

Coordinating payment, inventory, and shipping without one big transaction.

6 min read · advanced · beat Platinum to climb

Why a saga

Placing an order touches several services: payment, inventory, fulfillment, and notification. A single distributed transaction across them is fragile. A saga splits the work into local steps, each with a compensating action that undoes it.

Orchestration versus choreography

  • Orchestration: a central coordinator calls each step and triggers compensation on failure. Easier to trace.
  • Choreography: each service reacts to events from the previous one. Looser coupling but harder to follow.

Compensation

If payment succeeds but shipping cannot fulfill, the saga runs the compensation for payment, which is a refund, and releases the reserved inventory. Compensations must be idempotent because they may be retried.

Key idea

Model order placement as a saga of local steps each paired with an idempotent compensating action, so partial failures unwind cleanly without one global transaction.

Check yourself

Answer to earn rating on the learn ladder.

1. What is a compensating action in a saga?

2. Why must compensations be idempotent?

3. How does orchestration differ from choreography?