When a service is down or responds too slowly, every new request to it only makes things worse: the calling service’s threads hang waiting, queues and timeouts grow, and the failure spreads across the dependencies. The circuit breaker breaks this chain: after a series of failures it starts rejecting requests right away, giving the failing service time to recover.
Three states
| State | What happens | Transition |
|---|---|---|
| closed | requests pass as usual; errors and timeouts are counted | the failure rate exceeds the threshold — transition to open |
| open | requests are not sent; an error or a fallback response is returned right away | the wait expires, usually seconds — transition to half-open |
| half-open | lets one or several trial requests through | a success — transition to closed, a failure — back to open |
How it is configured and where it is used
Typical settings: how many recent calls are counted (for example, 50), what share of failures counts as a failure (for example, 50%), the minimum number of calls for an assessment, the wait in the open state, and which responses count as a failure — timeouts, network errors, 5xx codes. The wait is usually set to a few seconds and increased when failures repeat. The counting happens on the client side, separately for each dependency; the failure counter usually takes time into account, so that rare one-off failures do not open the circuit. Not every error is worth counting: a failure that the calling code handles itself through its ordinary logic is no reason to open the circuit.
The breaker is placed in HTTP clients between services, in libraries such as resilience4j and Polly, in API gateways and service meshes. It is combined with retries like this: the retry calls the service through the breaker and stops trying when the breaker has reported a non-transient failure.
CircuitBreaker cb = CircuitBreaker.of("payments", CircuitBreakerConfig.custom() .failureRateThreshold(50) // % of failures to open .slidingWindowSize(50) // how many calls to count .waitDurationInOpenState(Duration.ofSeconds(10)) .build());Where the term comes from
The pattern was popularised by Michael Nygard in the book “Release It!” in 2007 — by analogy with an electrical breaker that opens the circuit under overload and protects the wiring.
Sources
the term is written from these pagesVerified 8 Nov