The Circuit Breaker pattern is a stability mechanism that prevents a service from repeatedly attempting an operation that is likely to fail. It acts as a stateful proxy between a caller and a failing dependency, protecting local resources (threads, memory) from being exhausted by slow or dead downstream services.
A circuit breaker implements three primary states:
CallNotPermittedException. This gives the dependency time to recover.| Feature | Resilience4j | Hystrix (Netflix) | Sentinel (Alibaba) |
|---|---|---|---|
| Status | Active / Recommended | Maintenance Mode | Active |
| Threading | Functional / Decoupled | Thread-pool Isolation | Adaptive Throttling |
| State Storage | In-Memory (Atomic) | RxJava Observables | Slot-based Bucket |
| Complexity | Low | High | Medium |
Static timeouts ($2\text$) are often either too long (exhausting threads) or too short (causing false failures). Adaptive timeouts use the P99 latency of the last window plus a safety margin to set dynamic thresholds.
Instead of waiting for a 50% failure rate, predictive breakers monitor the Derivative of Latency. If latency is increasing exponentially, the breaker trips early to preempt a total outage.
Circuit breakers should be paired with BulkheadPattern to ensure that a tripped circuit for Service A does not starve the thread pool used for Service B.