Circuit Breaker

Reliability

Also known as: circuit breaker pattern

A circuit breaker is a design pattern that prevents an application from repeatedly trying an operation that is likely to fail, allowing the system to fail fast and recover gracefully instead of cascading failures.

Inspired by electrical circuit breakers, this pattern has three states: Closed (requests flow normally, failures are counted), Open (requests are immediately rejected without calling the failing service), and Half-Open (a limited number of test requests are allowed through to check if the service has recovered).

When the failure count exceeds a threshold in the Closed state, the circuit "trips" to Open. After a timeout, it moves to Half-Open. If test requests succeed, it returns to Closed; if they fail, it goes back to Open.

Circuit breakers prevent cascading failures in microservices architectures. Without them, a slow or failing downstream service can cause upstream services to exhaust their connection pools and thread pools, creating a domino effect.

Key configuration parameters include failure threshold (how many failures trip the circuit), timeout duration (how long to stay Open before testing), and success threshold (how many successes in Half-Open to close the circuit). Libraries like Resilience4j, Hystrix, and Polly provide circuit breaker implementations.

Related Terms

Ready to design?

Practice using circuit breaker in a real system design on Supaboard's interactive whiteboard.

Browse Challenges