Circuit Breaker
The Circuit Breaker design pattern, inspired by electrical engineering, is essential for managing service availability in software systems. Its primary role is to protect an overloaded service by failing fast, thus maintaining system stability and preventing cascading failures in distributed systems.
The Circuit Breaker implements the State design pattern, and it has three states:
- Closed State:
- The default state where requests are processed normally.
- Each exception increments a failure counter.
- The Circuit Breaker transitions to the
Open
state when the failure counter exceeds a specified threshold (maxFailures). - A successful request resets the failure count to zero.
- Open State:
- In this state, the Circuit Breaker short-circuits all requests by throwing an
ExecutionRejected
exception. - If a request is made after a configured reset timeout, the breaker transitions to the
Half...
- In this state, the Circuit Breaker short-circuits all requests by throwing an