System Design AI

The saga pattern in System Design Interviews: When to Use It and What to Say

In a system-design interview you often face a problem where several microservices must update their own databases as part of a single user request, but you cannot wrap the whole flow in a single database transaction. The saga pattern solves exactly that: it breaks the overall operation into a chain of local transactions, each with a compensating (undo) action that runs if something later fails.

The problem illustrated: an online order

Imagine an e-commerce checkout that touches three services:

  1. Inventory Service – reserves stock.
  2. Payment Service – charges the credit card.
  3. Shipping Service – creates a delivery ticket.

If the payment fails after the inventory is reserved, the order is left in a half-finished state. A single ACID transaction across three independent databases is impractical because each service owns its data and needs to scale independently. The system needs a way to either complete all steps or roll back the ones that already succeeded.

How a saga works, step by step

A saga can be implemented in two styles:

1. Orchestration

  • A central Saga Orchestrator receives the request.
  • It sends a command to Service A (reserve stock).
  • Service A replies success; the orchestrator then commands Service B (charge card).
  • If Service B fails, the orchestrator sends a compensating command to Service A to release the stock.
  • If Service B succeeds, the orchestrator proceeds to Service C (create shipment). A failure there triggers compensations for B and A.

2. Choreography

  • The initial request is placed on a message bus.
  • Each service listens for the event it cares about, performs its local transaction, and emits a new event for the next step.
  • If a service encounters an error, it publishes a failure event that the services which already completed their steps listen to and react to by undoing their work.

Both styles share three core ideas:

AspectOrchestrationChoreography
Control flowCentral orchestrator decides next stepDistributed, each service decides next step
CouplingServices talk to orchestrator (tight but explicit)Services talk to each other via events (looser)
Failure handlingOrchestrator issues compensations directlyCompensations flow as events

In either case the saga guarantees eventual consistency: after all compensations run, the system ends up in a state equivalent to having never started the transaction.

Classic interview questions where sagas appear

  1. Design an e-commerce checkout – the saga lives in the order-fulfillment flow, coordinating inventory, payment, and shipping.
  2. Design a travel booking system – booking a flight, hotel, and car rental must either all succeed or be rolled back; sagas handle the multi-step reservation.
  3. Design a banking money-transfer service – moving money between accounts in different banks uses a saga to debit one account, credit the other, and compensate if the credit fails.

In each case the saga is the mechanism that lets you keep the services independent while still providing a reliable end-to-end experience.

Trade-offs and the alternative interviewers love to ask about

DimensionSaga (orchestration)Saga (choreography)Alternative: Two-Phase Commit
LatencyExtra round-trip to orchestrator; modest increasePurely event-driven; can be faster but adds eventual consistency delaySynchronous; higher latency due to lock holding across services
ComplexityCentral logic, easier to reason aboutDistributed logic, harder to debugSimpler mental model but requires shared transaction manager
Failure handlingExplicit compensations from orchestratorCompensations spread across services; risk of missed eventsAutomatic rollback if any participant aborts
ScalabilityOrchestrator can become a bottleneck if not shardedNaturally scales with message busPoor scalability; lock contention across services

The alternative, Two-Phase Commit (2PC), gives strong consistency but forces all participants to hold locks until the commit phase finishes. In microservice environments that hurts throughput and availability, which is why interviewers often push you toward sagas.

A 30-second spiel you can recite

"A saga is a pattern for coordinating a series of local transactions across microservices. Instead of a single ACID transaction, each step commits locally and publishes an event. If a later step fails, compensating actions undo the earlier work, giving eventual consistency. You can run it with an orchestrator that directs the flow, or with pure choreography where services react to events. The trade-off is added latency and complexity versus the strong consistency of two-phase commit."

Common candidate mistakes

  • Treating compensations as true rollbacks – they often cannot fully revert side effects (e.g., a charged card may need a refund, not a simple undo).
  • Omitting idempotency – saga steps must be safe to repeat because retries are common; forgetting this leads to duplicate orders or double charges.
  • Mixing strong consistency with sagas – claiming the saga gives ACID guarantees confuses interviewers; sagas only provide eventual consistency.
  • Choosing the wrong style without justification – picking choreography for a simple three-service flow without explaining why the looser coupling matters.
  • Skipping failure propagation – not describing how a failure in Service C triggers compensations for A and B leaves the design incomplete.

How to practice this

  1. Open the System Design AI library and study the worked design that walks through a saga-based checkout flow.
  2. On a blank canvas, sketch the same flow: identify the services, choose orchestration or choreography, and write out the compensating actions for each step.
  3. Use the practice brief to rehearse the 30-second spiel and get feedback from the AI coach.

Questions people ask

When should I pick saga over two-phase commit?

Pick saga when services have separate data stores, need to scale independently, and can work with eventual consistency. Two-phase commit gives strong consistency but hurts performance and availability.

What’s the difference between orchestration and choreography?

Orchestration uses a central coordinator to issue commands and trigger compensations. Choreography lets services emit and listen to events, so the flow is driven by the messages themselves.

How do I ensure compensating actions are safe?

Make each step idempotent, keep enough context (like reservation IDs) to undo work, and design retries that continue until the compensation succeeds.

Can a saga run forever if compensations keep failing?

You should set a timeout and a fallback (such as manual reconciliation). Monitoring and alerts help detect and break such loops.