FullStack AI Hub
Studio
System Design · 05. Reliability
11 min
10 steps
Intermediate

Circuit Breakers & Retries

Stop cascading retry storms with jittered exponential backoff, retry budgets, Closed/Open/Half-Open circuit breakers, and bulkhead isolation.

System Design05. ReliabilityLesson 2 of 4
11 minIntermediate10 steps

Circuit Breakers & Retries

Stop cascading retry storms with jittered exponential backoff, retry budgets, Closed/Open/Half-Open circuit breakers, and bulkhead isolation.

RECO LATENCY
4,000 ms
API THREADS
98% hung
PAGE ERRORS
34%
GOODPUT
1,400/s
10s timeout wait2,200/sProduct API96%threads hungRecommendations100%4s stall!
healthy RPC
retry storm / stall
half-open probe
circuit open / fail-fast
In This LessonStep 1 of 10
What You Will Master
  • ✓Recognize how naive immediate retries multiply load 3×–10× and trigger cascading outages
  • ✓Tame retry waves using Exponential Backoff + Full Jitter and fleet-wide Retry Budgets
  • ✓Protect struggling dependencies using Closed, Open, and Half-Open Circuit Breakers with graceful fallbacks
  • ✓Contain slow downstream dependencies inside isolated Bulkhead thread/connection pools

Architectural Trade-Off Comparison Matrix

PatternBest ForKey Trade-Off
Backoff + Full JitterTransient network blips and temporary 503 throttlingStill sends load during prolonged outages if uncapped
Retry Budget (≤ 10%)Multi-hop microservice chains preventing exponential amplificationNeeds sliding-window tracking of retries vs original requests
Circuit Breaker (3-State)Failing fast (< 2 ms) when a downstream dependency is downRequires tuned failure thresholds and meaningful fallback behavior
Bulkhead IsolationStopping one slow non-critical service from starving checkout threadsPartitioned pools reduce peak sharing efficiency across endpoints

Step-by-Step Architectural Breakdown (10 Steps)

Full architectural walkthrough transcript and state transitions for Circuit Breakers & Retries.

STEP 01 · PROBLEMJump to step →

One slow dependency freezes your entire API

Your **Product API** calls the **Recommendations Service** on every page load with a 10-second timeout. Normally Recommendations replies in 25 ms.

When Recommendations suffers a database lock and slows to **4,000 ms**, every Product API worker thread hangs waiting—within seconds, **all 200 API threads are blocked** and even users who don’t care about recommendations get 503 errors!

watch:A slow dependency is far more dangerous than a fast-failing one—hanging sockets quietly drain thread pools upstream.

Cascading FailureThread StarvationTimeout Configuration
STEP 02 · PROBLEMJump to step →

Naive immediate retries create a 9× Retry Storm

To fix transient errors, every team adds `"retry 3 times immediately"` at each layer. Now when **DB** wobbles: Layer 1 retries 3×, Layer 2 retries 3× per attempt = **`3 × 3 = 9×` traffic** hammering an already dying service!

Even after the original bug heals, the self-inflicted **Retry Storm** keeps the downstream pinned at 100% forever—a **metastable outage**.

watch:Never retry at multiple stacked layers simultaneously—3 retries across 3 hops multiplies load by 3³ = 27×!

Retry StormRetry Amplification (k^N)Metastable Failure
STEP 03 · SOLUTIONJump to step →

Exponential Backoff + Full Jitter flattens retry spikes

Instead of retrying immediately, **Exponential Backoff** doubles the wait after each failure (`100 ms → 200 ms → 400 ms → 800 ms`, capped at a max). That gives overloaded servers breathing room to recover.

Crucially, add **Full Jitter** (`sleep = rand(0, cap)`): without randomness, 10,000 clients that failed at `12:00:00` all wake up in lockstep at `12:00:00.200` and smash the server again in synchronized waves!

good:AWS benchmarks proved Full Jitter cuts total completion time and server collision spikes by over 50% compared to plain exponential backoff.

Exponential BackoffFull JitterDesynchronized Retries
STEP 04 · TECHNIQUEJump to step →

Cap fleet-wide amplification with Retry Budgets

Even jittered retries are dangerous if 100% of requests start failing during a real outage—every single caller still sends 3× traffic! A **Retry Budget** tracks a sliding window and forbids retries from exceeding **10% of total normal requests**.

If error rate is 1%, retries fix almost every blip invisibly. If error rate jumps to 50%, the Retry Budget immediately **clamps total retry load to +10%**, preventing a retry storm automatically.

good:Google SRE & Envoy Service Mesh both recommend a 10%–20% Retry Budget over static per-request retry counts.

Retry Budget (10%)Sliding Window CapPer-Service Retry Limit
STEP 05 · SOLUTIONJump to step →

Circuit Breaker: trip OPEN and fail fast in 1 ms

Modeled after your home electrical panel, a **Circuit Breaker** wraps every downstream client. In the normal **CLOSED** state, traffic flows through while it counts errors in a rolling window.

Once error rate crosses **50%** (e.g., Recommendations DB dies), the breaker **trips OPEN**: for the next 30 seconds, every call **fails fast in < 1 ms locally** without ever touching the dying service—saving upstream threads AND letting the broken service reboot cleanly!

good:Failing fast in 1 ms locally protects upstream worker pools from ever hanging on dead sockets.

Circuit Breaker (CLOSED → OPEN)Fail-Fast Short CircuitError Threshold
STEP 06 · TECHNIQUEJump to step →

Half-Open state: probe gently before reopening the floodgates

After the Open cooldown timer expires (e.g., 30 seconds), the breaker does NOT immediately blast 100% of traffic back into the recovering service—that could knock it right back over!

Instead, it transitions to **HALF-OPEN** and allows just **3–5 canary probe requests** through. If all probes succeed, the breaker **closes** smoothly; if any probe fails, it snaps right back to **OPEN** for another cooldown.

idea:Half-Open probing turns abrupt recovery thundering herds into safe, self-verifying automatic healing.

Half-Open StateCanary Recovery ProbesSelf-Healing Circuit
STEP 07 · SOLUTIONJump to step →

Graceful Degradation: pair Open breakers with smart fallbacks

When a Circuit Breaker trips OPEN, what does the user actually see? Instead of an ugly red error banner, **Graceful Degradation** falls back to a fast cached **"Trending Items"** list or hides the optional widget cleanly.

Netflix and Amazon design every non-critical homepage row with a deterministic cached fallback so shoppers can still check out even when 3 personalization services are offline.

good:Decide your fallback BEFORE the outage: cached stale data, static defaults, or gracefully omitting optional UI widgets.

Graceful DegradationCached FallbackTier-1 vs Tier-2 Services
STEP 08 · TECHNIQUEJump to step →

Bulkhead Pattern: isolate thread pools like ship compartments

Ships divide their hull into watertight **bulkheads** so one hull breach cannot flood the entire vessel. Similarly, instead of one giant shared HTTP client thread pool, assign **separate bounded pools** per downstream dependency (`Checkout Pool: 80 threads`, `Analytics Pool: 20 threads`).

Even BEFORE a Circuit Breaker trips, a sudden stall in **Reviews/Analytics** can only ever fill its own 20-thread compartment—**Checkout’s 80 threads never feel a scratch**!

good:Bulkheads protect you during the first 10 seconds of a slowdown BEFORE error thresholds trip your Circuit Breaker.

Bulkhead IsolationThread-Pool PartitioningBlast-Radius Containment
STEP 09 · TECHNIQUEJump to step →

Deadline Propagation: stop doing work for expired callers

Imagine Gateway has a **500 ms overall timeout**, yet Service A waits 450 ms before calling Service B with a fresh 500 ms timeout. Even after the user already disconnected at 500 ms, Service B and the DB keep grinding away on **zombie work**!

Passing an absolute **remaining deadline** (`deadline_ms = 50 ms left`) in every gRPC/HTTP header lets downstream hops abort expired requests immediately before wasting precious DB CPU.

idea:gRPC has built-in deadline propagation—every downstream hop sees the exact remaining time budget and cancels automatically when time expires.

Deadline PropagationRequest CancellationZombie Work Prevention
STEP 10 · RECAPJump to step →

Fault-tolerant microservice mesh blueprint

Resilient distributed systems assume every dependency WILL eventually stall or crash. Layer **Deadlines**, **Bulkheads**, **10% Retry Budgets with Full Jitter**, and **3-State Circuit Breakers + Fallbacks** so one broken service never cascades.

Kill the downstream ML service under a 1.6× load surge below to watch the complete defense stack hold steady.

good:Use strict timeouts + deadlines, cap fleet retries to ≤ 10% with Full Jitter, bulkhead non-critical pools, and trip Circuit Breakers to cached fallbacks.

Resilience StackBreaker + Bulkhead + BudgetZero Cascade

Related Production Deep-Dives & Simulators

Related Systems Course
Free · Verifiable Credential

FS-201Production LLM Engineer

Design an observable full-stack LLM product from capability validation through interfaces retrieval evaluation security and operations.

37 concepts~35h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.