Circuit Breaker Pattern
The Circuit Breaker Pattern is a resilience design pattern that stops an application from repeatedly calling a service that is likely to fail, allowing it to recover and preventing cascading failures across a distributed system.
Definition
The Circuit Breaker Pattern is a resilience design pattern that stops an application from repeatedly calling a service that is likely to fail, allowing it to recover and preventing cascading failures across a distributed system.
Overview
A circuit breaker wraps calls to a remote dependency and tracks recent failures. It has three states: closed, where calls pass through normally; open, where calls fail immediately without hitting the downstream service once failures exceed a threshold; and half-open, where a limited number of test calls are allowed through to check if the dependency has recovered before fully closing the circuit again. This mirrors an electrical circuit breaker, which trips to stop current flow when something goes wrong. The pattern is especially important in Microservices systems, where a single slow or failing service can otherwise cause a cascading failure: callers pile up waiting on timeouts, exhaust their own thread pools or connections, and become unresponsive themselves. By failing fast once a threshold is crossed, a circuit breaker gives the failing dependency room to recover and protects the health of the calling service. Circuit breakers are typically combined with other resilience techniques such as retries with backoff, timeouts, and bulkheads (isolating resources per dependency), and they're commonly used alongside the Saga Pattern to gracefully handle a step failing mid-way through a distributed transaction. Popular implementations include libraries like Resilience4j, Polly, and Hystrix (now largely superseded), as well as built-in support in an API Gateway or service mesh. It is often deployed alongside Rate Limiting, since both protect service health under stress but from different directions — one reacting to failures, the other capping demand proactively.
Key Concepts
- Three states: closed (normal), open (failing fast), and half-open (testing recovery)
- Prevents cascading failures by stopping calls to an unhealthy dependency
- Configurable failure threshold and reset timeout before retrying
- Fails fast instead of letting callers hang on slow timeouts
- Often paired with retries, timeouts, and bulkhead isolation
- Widely available as a library (Resilience4j, Polly) or built into API gateways and service meshes
- Improves overall system resilience in distributed, service-to-service communication