Patterns
35 items
35 items
Preventing cascade failures in distributed systems
Circuit Breaker is a resilience pattern that prevents cascade failures by automatically stopping requests to failing services. Like an electrical circuit breaker, it has three states: Closed (normal operation), Open (failing fast without making requests), and Half-Open (testing if service recovered). When failure rate exceeds a threshold, the circuit "trips" open, giving the downstream service time to recover while failing fast to protect the caller. This pattern is essential for production systems - Netflix's Hystrix library popularized it and prevented countless outages.
Closed state operates normally, Open state fails fast without calling the service, Half-Open state tests recovery with limited requests. This state machine prevents a failing service from bringing down its callers.
After a timeout period (e.g., 30-60s), the circuit automatically enters Half-Open state to test if the service recovered. If test requests succeed, it closes; if they fail, it opens again.
When open, requests fail immediately without consuming threads, connections, or timeouts. This prevents thread pool exhaustion and allows the system to maintain capacity for other operations.
In microservices architectures, services depend on each other. When one service fails or becomes slow, it can bring down all services that depend on it - a cascade failure.
The cascade failure scenario:
Netflix built Hystrix after cascade failures brought down streaming. The library prevented countless outages and influenced all modern circuit breaker implementations including Resilience4j, Polly, and Spring Cloud.