Circuit Breaker
TechniqueReliabilityMidSeniorUpdated
Track failures from a dependency; once they exceed a threshold, open the circuit and fail fast for a cool-down period.
When to Use Circuit Breaker
Calling a dependency that can degrade your own health if you keep retrying. Without a breaker, your threads pile up on a slow call and the whole service stops responding.
In Practice
Netflix Hystrix popularized the pattern (now Resilience4j in the JVM world). Envoy / Istio have it built into the service mesh. Pattern: closed → open after N failures → half-open after timeout → closed if probe succeeds.
Sketch
Python
state = "CLOSED"; failures = 0
def call(fn):
if state == "OPEN" and now() < open_until: raise Tripped()
if state == "OPEN": state = "HALF_OPEN"
try:
result = fn()
failures = 0; state = "CLOSED"
return result
except:
failures += 1
if failures >= THRESHOLD:
state = "OPEN"; open_until = now() + COOLDOWN
raise