System Design

Circuit breakers: fail fast instead of waiting on a dead service

TL;DR

A circuit breaker sits between a caller and its dependency. When failures cross a threshold it “opens” and fails subsequent requests immediately instead of letting them hit timeouts. After a cool-down it lets a trial request through to check whether the service has recovered.

Three states

StateBehaviourMoves to
ClosedRequests flow normally; the breaker counts failures.Open once the failure threshold is hit (e.g. 5)
OpenFail immediately without calling the service — giving it room to recover.Half-open after a cool-down (e.g. 3s)
Half-openLet one trial request through.Closed on success, Open again on failure

In the video: during the 3-second open window, 15 requests get an answer instantly instead of each waiting 1000ms.

How to put it to work

  • Wrap every outbound call (third-party APIs, other internal services) so one dead dependency can’t take down the whole system.
  • Have a fallback while open: cached data, sensible defaults, or a friendly message.
  • Combine with short timeouts and jittered retries — the breaker stops pointless retries against a dead service.
  • Monitor: alert when a breaker opens; it’s an early incident signal.
  • Libraries: Resilience4j (Java), Polly (.NET), opossum (Node.js), or a service mesh such as Istio.