The Circuit Breaker pattern stops a service from repeatedly calling a dependency that is failing or very slow. After enough failures the breaker "opens" and calls fail immediately, which prevents threads and connections from piling up, stops cascading failures across microservices, and gives the struggling dependency room to recover.
It is one of the core resilience patterns for distributed systems, normally combined with timeouts, retries, bulkheads and fallbacks.
Service A calls service B, which calls service C. If C becomes slow, B's threads wait for C. B's thread pool fills up, so A's calls to B wait as well. Soon the whole chain is unresponsive, even though only C was unhealthy. Retries make it worse by adding more load to a service that is already struggling.
A circuit breaker cuts this chain. Once it detects that C is unhealthy, B stops calling it and fails fast (or returns a fallback), keeping its own resources free.
| State | Behaviour | Moves to |
|---|---|---|
| Closed | Calls pass through; failures and slow calls are counted | Open, when the failure or slow-call rate crosses the threshold |
| Open | Calls are rejected immediately without contacting the dependency | Half-open, after a wait duration |
| Half-open | A limited number of trial calls are allowed | Closed if they succeed, Open if they fail |
Typical configuration controls include the failure rate threshold (for example 50 percent), the size of the sliding window used to measure it, the minimum number of calls before the rate is evaluated, the wait time in the open state, and the number of trial calls in half-open.
Hystrix is in maintenance mode and no longer developed. Resilience4j is the standard library for Java today, and Spring Cloud Circuit Breaker provides an abstraction over it. With Spring Boot you can use annotations:
The matching configuration goes in application.yml:
The fallback method has the same parameters as the protected method plus a trailing exception parameter. When the breaker is open, Resilience4j throws CallNotPermittedException, which is routed to the fallback.
You can also use it programmatically without Spring:
503 Service Unavailable with a Retry-After header.Choose the fallback by business impact. A fallback must never pretend an operation succeeded when it did not, which matters for payments and writes.
Expose breaker state and metrics through Micrometer and the Spring Boot Actuator, and alert on open breakers. Useful signals are the state, failure rate, slow-call rate and the number of calls not permitted. An open breaker is a symptom of a dependency problem, so a dashboard that shows it helps you find the cause quickly.
A retry repeats a failed call hoping for success. A circuit breaker stops calls altogether once failures are frequent. They work together: retries handle brief glitches, the breaker handles sustained outages.
No. Netflix put Hystrix into maintenance mode. Use Resilience4j, or the Spring Cloud Circuit Breaker abstraction.
Use one for calls to dependencies that can fail or slow down independently, usually one breaker per dependency. Do not wrap trivial in-process calls.
Start with measured error and latency data from production, then tune. A low minimum call count causes a breaker to trip on small samples, so set it high enough to be statistically meaningful.
A circuit breaker protects your service from slow or failing dependencies by failing fast after repeated errors, then probing for recovery through the half-open state. Use Resilience4j in Java, pair it with timeouts, bounded retries and bulkheads, pick meaningful fallbacks, and monitor breaker state so outages are visible.