Circuit breakers and cooldowns
A circuit breaker counts recent failures to a dependency and, past a threshold, stops calling it for a cooldown, then sends a few trial calls to see whether it recovered. It keeps one sick dependency from dragging down its callers.
What it is
A circuit breaker is a proxy that sits between a caller and an operation that might fail, usually a remote dependency. It tracks recent outcomes and uses them to decide whether the next call is allowed to go out or should fail immediately. The point is to stop a caller from spending threads, connections and time on an operation that is likely to fail anyway, and to give the dependency room to recover instead of being hammered while it is already down.
The usual description is a state machine with three states. In Closed, requests pass through and the proxy counts recent failures; when the count crosses a threshold within a period, the breaker moves to Open and starts a timer. In Open, requests fail right away with an error returned to the caller. When the timer runs out, the breaker moves to Half-Open and lets a limited number of requests through: if they succeed it returns to Closed and resets its counters, and if one fails it goes back to Open and restarts the timer. That limited trial is what keeps a recovering service from being flooded the moment it comes back.
Measuring failure. Libraries make the "count of recent failures" concrete. Resilience4j 2.2.0 records call outcomes in a sliding window that is either count-based (the last N calls) or time-based (the calls of the last N seconds), and opens the breaker when the failure rate reaches a threshold, 50% by default. It can also open on slow calls: a call that runs longer than a configured duration counts toward a slow-call rate with its own threshold. A minimum number of calls has to be recorded before any rate is computed at all; with a minimum of 10, nine failures out of nine calls leave the breaker closed.
The cooldown. The time the breaker stays open before trying again is the cooldown. In Resilience4j 2.2.0 it defaults to 60 seconds, and by default nothing flips the state when that time passes: the first call made after the wait triggers the move to half-open, unless you enable a background transition. In half-open, 10 calls are permitted by default and the rest are rejected until those complete; the result of the trial decides whether the breaker closes or reopens. Envoy 1.36.2 takes a different line in its outlier detection: a host is ejected for a base time of 30 seconds multiplied by the number of times it has been ejected, capped at 300 seconds by default, with optional jitter so that many proxies don't all return to the same host at the same moment.
When the dependency tells you how long. A 429 Too Many Requests or 503 Service Unavailable response can carry a Retry-After header with a number of seconds or a date, and the Azure guidance treats such a response as grounds for tripping the breaker immediately and keeping it tripped for at least that long rather than retrying at once. Google's SRE book makes the complementary point from the server side: an overloaded service should return a distinct status so that callers back off instead of retrying.
| Knob | What it trades |
|---|---|
Window size (calls or seconds) | Small reacts fast to a burst but trips on noise; large is steadier but slow to notice |
Failure-rate threshold | Low protects the caller sooner; high tolerates a dependency that is flaky but mostly working |
Minimum calls before a rate counts | Low lets a quiet service trip on a handful of errors; high can leave a low-traffic breaker closed through a real outage |
Cooldown (time in Open) | Short probes often and recovers quickly, but can flap; long gives the dependency room but keeps failing after it has recovered |
Trial calls in Half-open | Few keeps the probe gentle; more gives a confident verdict at the price of more load on a recovering service |
Breaker and retry are different tools. A retry assumes the operation will eventually succeed and tries again; a breaker assumes it is likely to fail and refuses to try. The two combine: you retry through the breaker, and the retry logic stops when the breaker reports that the fault isn't transient. Retries without a breaker multiply under overload. One worked example: a database is overloaded while the back end, the front end and the browser code each make four attempts, so one user action can turn into 64 attempts on the database. The advice that follows: use randomized exponential backoff, cap retries per request, keep a server-wide retry budget, and retry at one layer rather than at each.
A retry can run the work twice. When a call times out, the server may still finish it: an overloaded server's late replies miss the client's deadline, the work is wasted and the client often retries. So a retried or redirected call can produce two side effects, and the design has to make a repeat harmless, which is the job of idempotency keys.
When to use it
Reach for a breaker when a remote call can fail or stall and you want to stop the failure from cascading into your own service: a dependency that has crashed, a shared resource returning overload errors, or a slow one that would otherwise tie up your threads. Routing traffic on live failure signals across regions and smoothing over intermittent connectivity are two more reasons. Pair the open state with a plan for the caller: degrade the feature, call an alternative that can do the same job, or tell the user to try later.
Give each independent back end its own breaker. Azure warns against one breaker for a resource with several independent providers behind it, such as a sharded store: merged error counts make the caller keep trying a shard that is down and block shards that are healthy. The same applies to a gateway with several deployments of the same model, or several regions of one provider: a breaker per deployment lets the router skip the open one and keep sending to the rest. The breaker pairs with failing open or closed: the breaker decides when to stop calling, and that choice decides what the caller gets instead.
Choose what counts as a failure deliberately. Resilience4j 2.2.0 lets you list the exceptions that count as failures and others that are ignored as neither failure nor success, and the split between retriable and nonretriable errors matters, since a malformed request keeps failing no matter how healthy the server is. Overload errors, timeouts and connection failures belong in the count; a client's bad input does not. You can go a step further and weight them, for example requiring more timeouts than hard failures before tripping.
When not to
Azure's guidance names several cases where a breaker is the wrong tool. Local, in-process resources such as an in-memory structure gain nothing from it and pay its overhead. If a dependency is built to absorb retries and a plain retry algorithm already works, the breaker can add complexity your system doesn't need. If waiting out a cooldown would be an unacceptable delay for the caller, the fail-fast period itself is the problem. Message-driven systems usually already park failed messages in a dead-letter queue for later handling, and that built-in isolation and retry handling is often enough; see Retries and dead-letter queues. And when a load balancer or service mesh already ejects unhealthy hosts, a second breaker in the application can be redundant.
A breaker is also the wrong answer when the problem is your own volume rather than the dependency's health. Google's adaptive throttling has each client track, over the last two minutes, how many requests it attempted and how many the back end accepted; once attempts exceed accepts by a factor K (2 in their usual setting), the client starts rejecting new requests locally with a probability that grows with the gap. That throttles traffic down to what the back end can take instead of cutting it off entirely, which is what you want when the back end is slow but serving. For the server-side version of the same idea, see Backpressure and load shedding.
Compared
| Mechanism | What it watches | What it does | When it is the better choice |
|---|---|---|---|
Circuit breaker | Failure or slow-call rate in a window | Stops calling for a cooldown, then probes with a few trial calls | A dependency that is down or overloaded, where calling it is wasted work |
Retry with randomized backoff | One failed call | Tries again after a growing, jittered delay | Brief transient faults where the next attempt is likely to succeed |
Retry budget | Share of calls that are retries | Stops retrying when retries exceed a share of traffic, 10% in Google's example | Partial overload: some tasks are busy but most of the fleet is fine |
Adaptive throttling | Ratio of attempts to accepts | Rejects a growing share of new requests at the client | A back end that is slow but serving; you want less traffic, not none |
Outlier ejection in a proxy | Consecutive 5xx or success rate per host | Removes one host from the pool for a growing ejection time | Many hosts behind one name, where one bad host should not fail the cluster |
In a picture
Step 1 of 3
Closed: calls pass, outcomes are recorded
The caller talks to the dependency through the breaker. Each outcome, success, failure or slow, lands in a sliding window that the breaker reads before letting the next call through.