Overview
Inspired by electrical circuit breakers, this pattern prevents an application from repeatedly trying to execute an operation that is likely to fail. This protects the system from cascading failures and gives the failing service time to recover.
States
- Closed: Requests flow normally. If failures exceed a threshold, the breaker 'trips' to Open.
- Open: Requests fail immediately with an error. After a timeout, the breaker moves to Half-Open.
- Half-Open: A limited number of requests are allowed. If they succeed, the breaker moves back to Closed. If they fail, it returns to Open.
Benefits
- Prevents resource exhaustion in the calling service.
- Improves system resilience.