Hystrix: The Circuit Breaker That Contains Cascading Failure
Why / The Problem
After the Strangler fig migration part’s decomposition, one request fans out to hundreds of downstream calls, each blocking a thread until it responds or times out. When one dependency — say recommendations — goes slow but not down (overloaded database, GC pause, bad deploy), every thread waiting on it is held for the full timeout. If all calls share one pool, that one dependency can exhaust the entire pool, and requests that never touch it fail too. One unbounded slow dependency becomes a full outage of unrelated features.
P(request succeeds) = pn → at n = 30 dependencies each 99.9% available, a request succeeds ~97% of the time
Fan-out multiplies unreliability. Only fallbacks — turning a dependency from required into optional — break the exponent.
Key: recommendations — the slow dependency · playbackAuth · userProfile · artwork · free slot
| No isolation (shared pool) | Hystrix (per-dependency bulkhead) | |
|---|---|---|
| Slow dependency's calls hold | Shared threads, up to the full timeout — healthy features starve too | Only its own small pool (or semaphore); others untouched |
| Caller experiences | A slow hang, then a timeout — wastes resources and the user's time | An immediate fallback (cached data, a default, a degraded UI) |
| Recovery | Pool stays exhausted while the dependency is slow; then a thundering herd | One trial request probes; full traffic resumes only if it succeeds |
How It Works
Every external call is wrapped in a HystrixCommand, which enforces isolation, a timeout, and outcome accounting:
- CLOSED — normal: calls go through; Hystrix watches the rolling window.
- OPEN — "tripped": the error rate crossed the threshold with enough volume to mean something (1 failure in 2 requests shouldn't trip it). Hystrix stops even attempting the call — no network call, no thread held, no timeout. The caller gets a fast, predictable, degraded response: a generic recommendation row instead of a spinner and then an error.
- HALF-OPEN — the probe: after the sleep window, exactly one trial request goes through. Success → close; failure → re-open and wait. This stops a fragile, just-recovering service from being hit with full traffic and knocked straight back down.
| Rolling window | 10 buckets × 1s ◆ Side read: what a "bucket" is → |
|---|---|
| Error threshold | ~50% |
| Minimum request volume | ~20 in window |
| Sleep window | ~5s |
| Isolation default | thread pool, per dependency |
| Cheaper alternative | semaphore, for in-process-fast calls |
Defaults, not laws — every one of these is tunable per command, and that tuning is where most of the real operational work lives.
Bulkheads: the half that works before the breaker trips
Bulkheads matter before the circuit trips — the part teams skip. Each dependency gets a small, dedicated thread pool (or, for calls so fast a context switch would dominate, a semaphore: cheaper, but it can't time out a blocked caller). A saturated pool simply rejects excess calls to its dependency; it structurally can't consume capacity meant for a healthy one.
✗ Shared pool — breaker works, bulkhead doesn't
// one pool, every dependency
ExecutorService shared =
newFixedThreadPool(200);
recommendations -> shared // slow!
playbackAuth -> shared
userProfile -> shared
artwork -> shared
// recommendations goes slow:
// its calls sit in `shared` for the
// full timeout, 200 threads drain,
// playbackAuth starves too.
// Everything degrades together
// for the entire window BEFORE
// the breaker even trips.✓ Per-dependency pools — damage is bounded
// one small pool per dependency
recommendations -> pool(10)
playbackAuth -> pool(20)
userProfile -> pool(15)
artwork -> pool(10)
// recommendations goes slow:
// its 10 threads fill, further
// calls are REJECTED instantly
// -> fallback. playbackAuth's 20
// threads are untouched.
// Blast radius = one feature,
// from the first slow request on.The two things Hystrix did that aren't isolation at all
Besides the bulkhead and breaker, Hystrix shipped two latency and load optimizations that only pay off because the fan-out is this wide — a big part of why "just add a circuit-breaker library" doesn't reproduce what Hystrix did for Netflix.
Request caching — don't ask the same question twice while building one page. Building one member's home page, the personalization row, the entitlement check and the UI header each ask for member profile 42. Hystrix calls the profile service once and hands all three the same answer. There's no timer or TTL: the cache lives exactly as long as a HystrixRequestContext that a servlet filter opens and closes around one HTTP request:
Java
HystrixRequestContext ctx = HystrixRequestContext.initializeContext();
try {
// ... build the whole page response ...
// getProfile(42) → real network call
// getProfile(42) → served from the context, no call
// getProfile(42) → served from the context, no call
} finally {
ctx.shutdown(); // the cache is discarded, whatever it holds
}The whole rule: same request → remember. Request ends → forget everything. Two members in the same millisecond share nothing; the same member a second apart shares nothing. Overlapping duplicates collapse too — the context holds the in-flight result, so a second caller subscribes to the first call instead of starting another.
Request collapsing — the one that is a time window. Calls to a dependency arriving within ~10 ms (default) merge into one batch: getProfile(42), getProfile(87), getProfile(13) become getProfiles([42, 87, 13]).
| Request caching | Request collapsing | |
|---|---|---|
| Merges | Same key → 1 call instead of 3 | Different keys → 1 multi-key call instead of 3 |
| Bounded by | The request context's lifetime — no timer | A timer, ~10 ms by default |
| Scope | Always exactly one request | REQUEST, or GLOBAL — batching across every user on that JVM |
| Cost | All callers share one object; one mutating it corrupts it for the rest | Up to the window's delay on every collapsed call |
Neither is a cache in the ordinary sense. "Keep a response for a few seconds and serve whoever asks" is the EVCache part’s EVCache — shared, TTL'd, replicated, over the network. Hystrix's cache is none of those: it exists only to stop one fan-out from asking the same question twice.
Where request caching stops: one hop
The cache is a ThreadLocal inside one JVM — a much tighter bound than "one request" suggests. In the shape that dominates fan-out, the BFF calls five services and each needs the same member: five separate request contexts that know nothing about each other.
BFF ──┬─→ service A ──→ user-service
├─→ service B ──→ user-service
├─→ service C ──→ user-service 5 calls for the same member.
├─→ service D ──→ user-service Hystrix dedupes none of them.
└─→ service E ──→ user-serviceIt dedupes within one hop only; once the question crosses a process boundary, every service asks again. That's much of why the Strangler fig migration part’s ~700 calls per home-page render is so large — the same few entities fetched over and over by different branches. Three real answers, Netflix's being the first:
| Approach | What it does | What it costs |
|---|---|---|
| Make the repeated call cheap EVCache · EVCache — Netflix's answer | All 5 calls still happen, but hit an in-AZ cache at sub-millisecond latency, never the user service's datastore. | Duplication becomes a connection and bandwidth problem, not a load problem. And you inherit the EVCache part’s AZ-loss behaviour: when the cache stops being cheap, all five calls get expensive at once. |
| Fetch once at the top, pass it down | The BFF resolves the member once and sends it to A–E. Duplication truly disappears. | Coupling: "member" is now in five contracts. At 700 services that's usually worse than the calls — why Netflix largely didn't. |
| Give something the whole query plan federated GraphQL gateway | A gateway that plans the query before executing merges every branch's need for the same entity at the same response path into one fetch per owning service — and the Apollo Router also drops duplicate keys inside each fetch. But the planner never sees "member 42", only types and paths, and calls a service makes inside its own code are invisible to it: with A–E as subgraphs that still call the user service themselves, the count stays at five until each dependency is written into the schema (@requires). | A new load-bearing edge tier. The merge must live where the plan lives — but it only reaches what the schema expresses, and a single GraphQL service with a per-request DataLoader dedupes member 42 better. Netflix's published reasons for federating were organisational, not fewer calls. Companion guide: From Device BFFs to a Federated Graph → |
Turbine aggregated Hystrix metrics fleet-wide into a live dashboard, turning "something is slow somewhere in 700 services" into "these three circuits are open, here's the blast radius and the root service."
The Invariants
- Guarantees: Once a circuit is open, calls to that dependency fail fast with a fallback, bounded by the sleep window — never an unbounded hang, and never resource use proportional to how bad the failure is.
- Does not guarantee: That the fallback is a good experience — only a fast, bounded, predictable one. Stale recommendations are still a degraded product; Hystrix makes that degradation the worst outcome, not the trigger for a wider outage.