CMD Guide
HomeSystem DesignMicroservices Patterns

Introduction

Retry Pattern: self-heal from blips without creating storms

In distributed systems, transient failures are normal: brief packet loss, a LB target draining, a dependency GC pause, a 503 during deploy. Many of these succeed if tried again moments later. The Retry pattern automatically re-issues a failed operation under policy so users do not see avoidable errors.

The danger is not "retrying" — it is retrying unsafely: non-idempotent operations, no backoff (thundering herd), unbounded attempts (latency and load explosions), or retries stacked at every layer of a call chain (multiplicative amplification).

Mechanism

  1. Attempt operation.
  2. On retryable failure (timeout, 502/503/429, connection reset), wait backoff(attempt) with jitter.
  3. Retry until success or max attempts / deadline.
  4. On non-retryable failure (400, 401, 404, business rule), fail immediately.

Exponential backoff + full jitter (common form): sleep random in [0, min(cap, base * 2^attempt)]. Jitter desynchronizes clients so recovery is not a synchronized stampede.

Worked example: charge card timeout

Checkout calls Payment with 200 ms timeout. At t=0 request R1 is sent; Payment charges the card at t=50 ms but the response is lost. Caller sees timeout — uncertain outcome (two generals).

PolicyWhat happensOutcome
No retryUser sees error; card may already be chargedSupport nightmare
Naive retry, no idempotency keyR2 charges againDouble charge
Retry with idempotency key KR2 carries K; Payment returns original successSafe; one charge

Rule: never retry a side-effecting call unless the receiver can dedupe (idempotency key, natural unique constraint, or truly pure read).

Amplification math (why budgets matter)

Edge makes up to 3 attempts, Service A makes up to 3 attempts (3 attempts each, counting the original — not 3 retries on top of it), Service B is the leaf. Worst-case calls to B per user request = 3 × 3 = 9 (and deeper chains get worse). During an outage this is a self-DDoS. Cap with: max attempts, overall deadline, and prefer retry at one layer (usually the edge or the owner of the idempotency key), not every hop.

When NOT to retry

Failure / operability

Decision defensibility

Why not infinite retry until success? Unbounded tail latency and infinite load on a sick dependency. Why not only circuit breaker? Breakers handle sustained failure; retries handle short blips without opening. Use: timeout → limited retry with jitter on idempotent ops → breaker when failure budget exceeded.

Drill ladder

  1. Q: Timeout then success on server — do you retry? A: Yes only with idempotency; outcome is uncertain without it.
  2. Q: Why full jitter vs fixed 1 s sleep? A: Fixed sleep aligns clients into waves; jitter spreads load.
  3. Q: HTTP 400 on create user — retry? A: No; fix the request.
🤖 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