12. Reliability and observabilityCircuit breakers
Circuit breakers
A circuit breaker is a guard in front of calls to another service that stops sending requests once that service is clearly failing, named after the electrical switch that trips to protect a circuit. Normally it’s closed and requests pass through while it counts failures. When failures cross a threshold it opens, and calls fail immediately instead of waiting on timeouts, which keeps your own threads free and gives the struggling service room to recover. After a cool-down it goes half-open and lets a few trial requests through: if they succeed it closes again, if not it reopens. It’s often paired with bulkheads, which give each dependency its own limited pool of resources so one slow service can’t exhaust everything.
In this lesson: A closed, open, half-open state machine. Bulkheads.