A circuit breaker wraps calls to a remote dependency and, when failures pass a threshold, “trips” to fail fast for a period instead of continuing to call something that’s broken.

Popularised by Michael Nygard in Release It!, the circuit breaker is one of a small family of patterns (timeouts, retries with backoff and circuit breakers) that every service calling another service needs.

The problem

When a dependency slows down or fails, callers keep calling it. Threads and connections pile up waiting, the caller runs out of resources and starts failing too, and its own callers follow. One slow service can take down a whole system. Naive retries make it worse: a struggling service gets hit with more traffic exactly when it can least cope.

The solution

Timeouts: never call anything without one. Without a timeout, a slow dependency becomes your slow service.

Retries with exponential backoff and jitter: retry transient failures, waiting longer each time (for example 100ms, 200ms, 400ms) with some randomness added so that thousands of clients don’t retry in lockstep. Cap the number of retries, and only retry operations that are safe to repeat.

Circuit breaker: track failures for each dependency.

Circuit breaker statesClosedcalls pass throughOpenfail fastHalf-opena few trial callsfailures pass the thresholdafter a cool-off periodtrial failstrial succeeds
Closed, open and half-open: the breaker fails fast while a dependency recovers, then cautiously tries again.

When the circuit is open, degrade gracefully: return a cached value, a default, a reduced experience or a clear error, rather than hanging.

When to use it

Trade-offs

Many service meshes, SDKs and libraries implement these for you. Use them rather than writing your own, but understand the settings.