The Circuit Breaker Pattern: Stop Calling a Dead Service
When a dependency goes down, every request blocks on a timeout and your thread pool fills up. One broken service takes the whole system with it. The circuit breaker pattern detects sustained failures and stops sending traffic, giving the downstream time to recover.
The breaker tracks failures in a sliding window and transitions through three states: closed (normal), open (rejecting all calls), and half-open (probing with limited requests). Key parameters include the failure rate threshold, minimum call volume, wait duration before probing, and number of half-open test calls. Each dependency gets its own breaker instance.
Unlike retries, which repeat calls hoping for success, a breaker cuts traffic entirely once the error rate proves the service is broken. In the open state you serve cached data, degrade gracefully, or return an honest error — but you don't hold threads waiting on a dead endpoint.