CMD Guide
HomeSystem DesignMicroservices Patterns

Introduction

Circuit Breaker: fail fast so the rest of the system lives

Remote calls fail. They also hang. A hung dependency is worse than a dead one: threads, connections, and memory stay occupied waiting, until the caller is as dead as the callee. The Circuit Breaker pattern (Nygard, Release It!) stops sending traffic to a dependency that has crossed a failure budget, fails fast (or serves a fallback), then carefully probes for recovery.

Electrical analogy: trip the breaker to protect the house wiring. Software analogy: protect the caller's finite concurrency so one bad neighbor cannot take down the process.

Mechanism: three states

StateBehaviorTransition
ClosedCalls flow; failures counted in a sliding window→ Open when failure rate or slow-call rate exceeds threshold
OpenCalls short-circuit immediately (error or fallback); no load on dependency→ Half-Open after cooldown timer
Half-OpenAllow a small number of trial callsSuccess budget met → Closed; failure → Open again

Critical prerequisites the breaker does not replace: a per-call timeout (without it, the first slow wave exhausts the pool before the breaker opens) and a decision on what "failure" means (timeouts, 5xx, connection refused — not 4xx validation errors).

Worked example with numbers

Order Service → Payment Service. Order has 100 worker threads. Payment p99 is normally 80 ms; timeout set to 300 ms. At 200 RPS to Payment, in-flight ≈ 200 × 0.08 = 16 — fine.

Payment degrades: calls now take ~2.5 s to complete, so every call is cut off by the 300 ms timeout and counted as a failure. Without a breaker:

With a breaker (e.g. open after 50% failures in a 20-call window, cooldown 10 s):

When a circuit breaker is the wrong fix

Prefer: timeouts always; retries only on idempotent ops; bulkheads so one dependency's wait cannot steal all threads; breakers to stop hammering a known-sick dependency.

Failure / operability

Decision defensibility

Why not only retries? Retries amplify load on a sick service and need idempotency. Why not only bulkheads? Bulkheads cap concurrency but still allow continuous load at the cap. The breaker stops the load after evidence of systemic failure. Use all three: timeout + bulkhead + breaker (+ careful retry).

Drill ladder

  1. Q: Why must timeout sit under the breaker? A: Breaker counts failures; without timeout, calls hang and never become "failures" until the pool is already empty.
  2. Q: Half-open admits 50 probes from 50 pods at once — what goes wrong? A: Recovering dependency sees a thundering herd and fails probes → stuck open longer.
  3. Q: Payment returns 400 for bad card data — should that open the breaker? A: No. Client/validation errors are not dependency health.

The pages that follow work the state machine, tuning, and combination with retries and bulkheads in production detail.

🤖 Don't fully get this? Learn it with Claude

Stuck on Introduction? 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 **Introduction** (System Design) and want to truly understand it. Explain Introduction 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 **Introduction** 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 **Introduction** 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 **Introduction** 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