Circuit Breaker is a distributed system pattern inspired by electrical circuit breakers. Just as a breaker cuts the circuit to prevent a fire when excess current flows, when service calls fail repeatedly it automatically blocks requests to prevent Cascading Failure across the entire system.
It operates in three states. In the Closed state, it passes requests through normally while monitoring the failure rate. When failures exceed the threshold, it switches to the Open state and fails all requests immediately (Fail Fast). After a certain period of time, it enters the Half-Open state and uses a limited number of requests to check whether the service has recovered.
Key parameters include the Failure Threshold, Timeout, Wait Duration, and Permitted Calls in Half-Open. These values must be tuned to the characteristics of the service and its SLA.
It is used together with a Fallback strategy. When the circuit is in the Open state, graceful degradation can be implemented, such as returning cached data, providing default values, or calling an alternative service. This protects the system while maintaining the user experience.
Key implementations include Resilience4j for Java, Netflix Hystrix (currently in maintenance mode), pybreaker for Python, and opossum for Node.js. In Kubernetes environments, service meshes such as Istio and Envoy provide circuit breakers at the infrastructure level.