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.

Thread-pool occupancy when recommendations goes slow. With one shared pool of 200 threads, recommendations holds every thread within about a second and playbackAuth, userProfile and artwork are left with none. With a small pool per dependency, recommendations fills its own 10 and the other three pools are untouched.
One slow dependency, drawn as thread-pool occupancy. Both panels are the same incident, and every square is one thread. Above, the slow dependency ends up holding all 200 — so features that never call it have nowhere to run. Below, it fills its own ten and stops there; the other three pools are not defended against it, they are simply not reachable from it.

Key: recommendations — the slow dependency · playbackAuth · userProfile · artwork · free slot

No isolation (shared pool)Hystrix (per-dependency bulkhead)
Slow dependency's calls holdShared threads, up to the full timeout — healthy features starve tooOnly its own small pool (or semaphore); others untouched
Caller experiencesA slow hang, then a timeout — wastes resources and the user's timeAn immediate fallback (cached data, a default, a degraded UI)
RecoveryPool stays exhausted while the dependency is slow; then a thundering herdOne 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:

What one HystrixCommand does to a single call. The caller thread calls dependency X and the call passes three gates in order. Gate 1, the breaker: if it is OPEN the call is short-circuited — X is never called, with no thread and no timeout. If CLOSED or HALF-OPEN it goes on. Gate 2, the bulkhead: X's own pool of 10 threads, never Y's or Z's; if no thread is free the call is rejected instantly. Gate 3, the timeout: the wait is capped whatever X does; an error or timeout fails. Any of those three failures returns the same fallback: a cached value, a default, or a degraded UI element, while a call that returns in time is the real response. Every outcome — success, failure, timeout, rejection — is counted in a rolling window of 10 one-second buckets, and that window is the state gate 1 reads: at 50 percent errors or more over at least 20 requests it opens for about 5 seconds, then allows one probe.
What one HystrixCommand does to a single call. Isolation, timeout and outcome accounting are not three choices — they are three things that happen to every call, in this order.
The three circuit states, and what a call does in each. The table has one row per state. Row one, CLOSED, normal operation and the starting state: the call is attempted, it runs on X's own thread pool under X's own timeout, and the outcome lands in the rolling window; the caller gets the real response. Row two, OPEN, tripped: the call is not attempted at all, no network call, no thread held, no timeout incurred; the caller gets an instant fallback on every request. Row three, HALF-OPEN, probing: exactly one trial call goes to X and all other requests are still short-circuited, so that one call returns the real response and every other request gets the fallback. The transitions form a cycle, not a chain. CLOSED moves to OPEN when errors reach about 50 percent and there are at least about 20 requests in the rolling window. OPEN moves to HALF-OPEN after the roughly 5 second sleep window expires, nothing having been attempted while it was open. From HALF-OPEN, a probe that succeeds returns to CLOSED and resumes, and a probe that fails returns to OPEN for another roughly 5 seconds. Nothing in the machine inspects the dependency: its only input is the rolling window of outcomes, 10 buckets of 1 second each.
The three circuit states, and what a call does in each. The state machine is an accounting rule with a cool-off: it stops attempting a call it has evidence will fail, then spends exactly one request to find out if that is still true.
  • 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 window10 buckets × 1s ◆ Side read: what a "bucket" is →
Error threshold~50%
Minimum request volume~20 in window
Sleep window~5s
Isolation defaultthread pool, per dependency
Cheaper alternativesemaphore, 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 cachingRequest collapsing
MergesSame key → 1 call instead of 3Different keys → 1 multi-key call instead of 3
Bounded byThe request context's lifetime — no timerA timer, ~10 ms by default
ScopeAlways exactly one requestREQUEST, or GLOBAL — batching across every user on that JVM
CostAll callers share one object; one mutating it corrupts it for the restUp 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-service

It 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:

ApproachWhat it doesWhat 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 downThe 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.