veda.ng
Back to Glossary

Circuit Breaker

A circuit breaker is a software design pattern that prevents cascading failures in distributed systems by detecting when a service is failing and temporarily stopping requests to it, allowing time for recovery. The pattern is named after electrical circuit breakers that trip to prevent damage from power surges. Without circuit breakers, when Service B starts failing, Service A continues sending requests, tying up resources waiting for timeouts, potentially exhausting its own capacity and propagating the failure upstream. The circuit breaker maintains three states: Closed (normal operation, requests flow through, failures are counted), Open (failure threshold exceeded, requests fail immediately without attempting the call), and Half-Open (recovery testing, a few requests are allowed through to check if the service has recovered). If test requests succeed, the circuit closes; if they fail, it opens again. Configuration parameters include failure threshold (how many failures trigger opening), timeout duration (how long to stay open before testing), and success threshold (how many successes needed to close). Circuit breakers provide graceful degradation: instead of hanging or crashing, the system returns fast failures that can be handled appropriately. They also reduce load on failing services, giving them breathing room to recover. Netflix's Hystrix popularized the pattern; modern implementations include resilience4j and Polly.