advanced
Circuit breaker
Stop calling a failing dependency temporarily so resources recover, users get fast failure, and probes can test restoration.
A circuit breaker tracks failure rate to a dependency. Closed state allows calls; open state fails fast without loading the sick service; half-open probes occasional calls to detect recovery. This preserves caller resources and prevents cascading failure.
Trade-off: fast failure and protection versus stale open state blocking legitimate traffic after recovery.
On interviews: describe state transitions and thresholds; combine breaker with fallback and bulkhead.
Common pitfalls: breaker on every call without shared state; thresholds too sensitive; no half-open probes.
Checklist:
- Configure failure rate and sliding window.
- Fail fast with clear errors when open.
- Probe recovery in half-open state.
- Expose breaker metrics on dashboards.