CMD Guide
HomeSystem DesignMicroservices Patterns

System Design Examples

Saga pattern: designs that hold up under hostile review

A saga coordinates a multi-service business flow as local transactions + compensations, not as distributed ACID. The interesting part is not listing industries that "use sagas" — it is tracing failure, naming the pivot, and rejecting the wrong tool (local txn or 2PC) when it would win.

Worked example: food delivery (orchestrated)

Order 8842, total $27.50, restaurant r-119. Orchestrator = Order service.

#StepLocal commitResult
T1Create orderstatus=PENDINGOK
T2Authorize payment$27.50 hold (authId=A7)OK
T3Confirm restaurantticket=K42 reservedOK
T4Assign couriersearch 90sFAIL — none available
C3Release restaurantcancel K42OK
C2Void authvoid A7OK
C1Cancel orderCANCELLED / NO_COURIEROK

Design choices that matter: authorize-then-capture so C2 is a clean void; courier assignment before capture so you can still compensate money; after courier en-route + capture you pass the pivot — only roll forward.

Travel booking (multi-party)

Flight + hotel + car across vendors. Often choreography or a booking orchestrator with timeouts. Compensations are vendor-specific cancel APIs (sometimes with fees). First bottleneck: long-held vendor reservations under inventory contention. Rejected alternative: 2PC across airline APIs — they will not hold XA locks for your cart.

E-commerce checkout

Order → Payment → Inventory → Shipping. Same saga shape. Inventory failure after payment hold → void/refund compensation. Paid trade-off: user may briefly see "processing" and inventory systems see PENDING holds (no isolation) — so downstream consumers must treat PENDING as a semantic lock: reporting excludes it, fulfilment won't pick it, and a second saga touching the same SKU either waits or fails fast rather than double-committing.

Banking — the corrected lesson

Transfer $500 savings→checking inside one bank is one local ACID transaction, not a saga:

BEGIN;
  UPDATE accounts SET balance = balance - 500
    WHERE id = 'savings' AND balance >= 500;
  -- if 0 rows were updated: insufficient funds -> ROLLBACK and stop
  UPDATE accounts SET balance = balance + 500 WHERE id = 'checking';
COMMIT;

The affected-row check is load-bearing: without it, an insufficient-funds transfer debits nothing but still credits $500 — the transaction is atomic, yet the invariant breaks, because ACID never checks business rules you didn't express. (A CHECK (balance >= 0) constraint is the belt-and-braces version.) Same idiom, same guard, as the stock reservation in the worked saga example.

Model as saga only for inter-bank or truly split services/databases. Using saga "because there are two steps" is an architecture smell.

Hostile design-review table

ScenarioFirst bottleneck / failureRejected alternativeTrade-off paid
Food delivery orderCourier SLA miss mid-saga; compensation latencySingle DB for restaurant+courier+pay (ownership/scale fights) No isolation; SMS may fire before pivot if ordered wrong
Travel multi-vendorPartial books + cancel fees; orchestrator crash state2PC across vendors Eventual consistency; complex compensations
Intra-bank transfer Saga itself (wrong tool) N/A — use local ACID
Choreography-only checkout >5 stepsImpossible incident narrative ("who owns step 4?") Keep pure choreography for purity Prefer orchestrator for visibility

When NOT to use a saga

Operability

Drill ladder

  1. Q: Why authorize-then-capture in the food example? A: Compensation is void of hold, not refund of captured funds — simpler, faster, less customer pain.
  2. Q: Orchestrator dies after C3 succeeds, before C2. What must exist? A: Durable saga log/state machine that resumes compensation from last completed step.
  3. Q: Is "debit + credit" always a saga? A: No — only if accounts are in separate transactional domains.
🤖 Don't fully get this? Learn it with Claude

Stuck on System Design Examples? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **System Design Examples** (System Design) and want to truly understand it. Explain System Design Examples from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **System Design Examples** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **System Design Examples** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **System Design Examples** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes