In a microservices architecture, Service A depends on Service B. If Service B becomes slow or unresponsive, Service A's threads will pile up waiting for responses, eventually exhausting Service A's resources and causing it to fail too. This failure then cascades to Services C, D, and E that depend on Service A. A single failing service brings down the entire system.
The Circuit Breaker Pattern prevents this cascading failure by wrapping calls to external services in a monitoring object that can short-circuit requests when the downstream service is unhealthy.
All requests pass through to the downstream service normally. The circuit breaker monitors the failure rate of these requests.
The circuit breaker immediately rejects all requests without even attempting to call the downstream service. It returns a fallback response (e.g., cached data, a default value, or a friendly error message) instantly.
The circuit breaker allows a limited number of test requests to pass through to the downstream service.
Popular libraries for implementing the Circuit Breaker pattern: