MentorNode
Start free
Data, Storage & ConsistencyHarddesign-distributed-transactions

Design Distributed Transactions with Sagas

Design a booking flow that spans payment, inventory, and notification services, where there is no shared transaction to roll back — only compensations you have to write yourself.

SagaCompensating TransactionsTransactional OutboxTwo-Phase Commit
Traffic & Capacity Estimates:

5k multi-service transactions/second · 6 participant services · 99.999% settlement correctness

Functional Requirements

  • •Execute a multi-service workflow as a sequence of local transactions, each publishing an event.
  • •On any step's failure, run compensating transactions for every completed prior step, in reverse.
  • •Persist saga state durably so an orchestrator crash resumes rather than abandons in-flight work.
  • •Surface a terminal state (committed, compensated, or stuck) for every saga to operators.

Non-Functional Requirements

  • •No lost or duplicated effects — every step is idempotent and every event is delivered at least once.
  • •A single slow participant must not block unrelated sagas.
  • •Stuck sagas must be detectable and manually resolvable; silent partial states are unacceptable.

Back-of-the-Envelope Math

  • 5k sagas/s * 6 steps = 30k step executions/second across the fleet.
  • At a 2% failure rate, 100 compensation chains per second must run correctly under load.

Key Architectural Trade-offs

  • Orchestration (a central coordinator — visible, testable, a new service to own) vs choreography (services react to events — decoupled, and nobody can explain the flow).
  • Sagas trade atomicity for availability: intermediate states are visible to users, so 'reserved' and 'pending' become part of your domain model.
  • Two-phase commit gives real atomicity where all participants support it, at the cost of blocking locks and an availability ceiling set by the weakest node.

Click or drag a component onto the canvas, then connect the handles to draw the data flow.

3 nodes · 2 edges

Components · 35

Client & Edge4
Compute & Gateway7
Storage & Caching11
Messaging & Streaming6
Coordination & Ops5
Intelligence2
Canvas overview