Resilience · Pattern
Circuit breaker
Watch calls to a dependency fail. Once the failure rate crosses a threshold, stop calling it at all, then let a few trial calls decide when to start again.
Netflix built Hystrix, the library that made the circuit breaker famous, to “stop cascading failure and enable resilience in complex distributed systems where failure is inevitable.” The rule it shipped is short: when too many calls to a dependency fail, stop calling it for a while, then let “the next single request” through as a test.
Netflix has since stepped back: “Hystrix is no longer in active development, and is currently in maintenance mode.” The pattern lives on in maintained libraries, and this page takes its numbers from one of them, Resilience4j.
Wrap calls to a dependency and watch them fail. Once the failure rate over a window of calls crosses a threshold, the breaker opens and calls fail at once without reaching the dependency, then trial calls decide whether to close it again.
What it is
A circuit breaker sits between your code and a dependency and keeps score. In Martin Fowler’s words, “You wrap a protected function call in a circuit breaker object, which monitors for failures.” It is always in one of three states.
Closed is normal: calls go through, and the breaker records how each one ended. Open is refusing: every call fails at once, “without the protected call being made at all.” Half-open is the test: a few trial calls go through, and how they do decides which way it goes next.
The open state is the point. While it is open you are not waiting for a timeout and not holding a thread: the error comes back immediately, and the struggling dependency gets no load from you.
The problem
The danger is not that a dependency fails. It is that your callers keep waiting on it, and every waiting call is holding something:
“These blocked requests might hold critical system resources, such as memory, threads, and database connections. This problem can exhaust resources, which might fail other unrelated parts of the system that need to use the same resources.”Microsoft, Azure Architecture Center
Note other unrelated parts. A dependency you barely use can take down work that never touches it, because they share a pool of threads or connections. That is how one sick service becomes a cascading failure. Fowler names what a breaker buys back: “You avoid waiting on timeouts for the client, and a broken circuit avoids putting load on a struggling server.”
From first principles
Take Resilience4j’s defaults and a dependency that starts failing half of its calls. Follow one breaker through all three states.
- Closed, counting. The breaker keeps the outcome of the last 100 calls. Until it has recorded 100, it will not trip, even if every one of them failed.
- Trip. 50 of the last 100 calls fail: 50 ÷ 100 = 50%, which meets the 50% threshold, so the breaker opens.
- Open. For the next 60,000 ms, every call is rejected at once, with no call made. Say your service makes 20 calls a second to that dependency (an example rate): that is 20 × 60 = 1,200 calls the struggling dependency never receives.
- Half-open. Once 60 s have passed, the next call moves the breaker to half-open, and it lets 10 trial calls through. By default Resilience4j waits for that call: it does not leave the open state on a timer alone.
- Decide. If 5 or more of the 10 trials fail (50% or more), it opens again for another 60 s. If fewer than 5 fail, it closes.
The general rule:
open when failed ÷ recorded ≥ threshold, once recorded ≥ minimum example 50 ÷ 100 = 50% ≥ 50%, and 100 ≥ 100
The solution
A breaker that helps rather than hurts gets five things right:
- Trip on a rate over a window, after a minimum number of calls. Ten failures out of ten is an outage; ten out of ten thousand is noise. Fowler suggests “tripping once you get, say, a 50% failure rate.” The minimum stops a quiet service from tripping on a handful of errors.
- Count only the failures that mean the dependency is unhealthy. Fowler: “Not all errors should trip the circuit, some should reflect normal failures and be dealt with as part of regular logic.”
- Put a timeout on every call it wraps. A call that never returns gives the breaker no outcome to record. The timeout gives it one.
- Test recovery with a few calls, not all of them. Azure: “The Half-Open state helps prevent a recovering service from suddenly being flooded with requests.”
- Decide what the caller does while the breaker is open, before you need it. Fowler: “clients using them need to react to breaker failures.”
Patterns: three libraries, three bets
The state machine is settled. The defaults are not. As of October 2026:
| Default | Resilience4j 2.2.0 | Hystrix | Polly v8 |
|---|---|---|---|
| Trip threshold | 50% | 50% | 10% |
| Window | last 100 calls | 10 s | 30 s |
| Minimum calls before it can trip | 100 | 20 | 100 |
| Time spent open | 60 s | 5 s | 5 s |
Polly trips at a fifth of the failure rate the other two use, and Resilience4j stays open twelve times as long (60 s against 5 s). Neither is wrong: each is a bet about how much evidence is enough and how long recovery takes. Copy a breaker config from a blog post and you inherit somebody else’s bet.
Do
- Trip on a failure rate over a window, with a minimum call count.
- Put a timeout on every call the breaker wraps.
- Log every state change (Fowler: breakers are “a valuable place for monitoring”).
- Give operators a manual reset (Azure).
- Pair a breaker with a bulkhead (Resilience4j).
Don’t
- Don’t let every exception trip it (Fowler).
- Don’t open on a handful of calls (Resilience4j and Polly both require a minimum).
- Don’t switch from open to half-open too quickly (Azure: the breaker can “fluctuate”).
- Don’t assume a breaker is free (Amazon Builders’ Library).
Trade-off
A breaker adds a second mode to your service: the mode where it refuses to make a call that might have worked. Amazon’s Builders’ Library is direct about what that costs:
“Unfortunately, circuit breakers introduce modal behavior into systems that can be difficult to test, and can introduce significant addition time to recovery. We have found that we can mitigate this risk by limiting retries locally using a token bucket.”Marc Brooker, Amazon Builders’ Library
Both costs follow from what the open state is. It is a code path that rarely runs, so it is the path least likely to work when it finally does. And while the breaker is open it is not calling a dependency that may already have recovered, so the breaker itself can extend the outage. A token bucket is a budget of retries held by the caller, which Brooker describes as one that “allows all calls to retry as long as there are tokens, and then retry at a fixed rate when the tokens are exhausted.” It caps what retrying costs, and it acts on the retries rather than on the first attempt.
None of that rules a breaker out. It means the open path needs testing like any other path, and the open time is a number to choose, not inherit. Netflix, for its part, says its focus has shifted to adaptive implementations that react to an application’s real time performance rather than to settings chosen in advance.
How it fits with the rest
A breaker interrupts a cascading failure by removing load. That is the opposite move to a retry storm, where every layer answers failure with more calls. It needs a timeout in front of it, so that a hung call becomes a failure it can count. Its nearest relative is the bulkhead, which gives each dependency its own pool; Azure: “If a service begins to fail, it only affects the connection pool assigned for that service.” Resilience4j treats the two as partners: “You can combine a Bulkhead and a CircuitBreaker.”
Practise it in two minutes
Predict what happens, watch it move, change the numbers, and get tested again before you forget.
Open Circuit breaker in the app →Related
Sources
- Netflix, Hystrix README
- Netflix, Hystrix wiki, “How it Works”
- Netflix, Hystrix wiki, “Configuration”
- Martin Fowler, “Circuit Breaker”, 6 March 2014
- Resilience4j documentation, CircuitBreaker
- Microsoft, “Circuit Breaker pattern”, Azure Architecture Center
- Microsoft, “Bulkhead pattern”, Azure Architecture Center
- Polly v8 documentation, “Circuit breaker resilience strategy”
- Marc Brooker, “Timeouts, retries, and backoff with jitter”, Amazon Builders’ Library