Web apps & software

What is the circuit breaker pattern?

The circuit breaker pattern wraps calls to another service so that, after repeated failures, the app stops calling it for a short while and fails fast instead of waiting on timeouts that pile up.

Three states

Closed: calls go through normally and failures are counted. Open: after too many failures, calls are rejected immediately with a fallback. Half-open: after a pause, a few trial calls test whether the service has recovered; success closes the breaker, failure opens it again.

Why it matters

Imagine a booking page that calls a maps service for every quote. The maps service slows to a crawl, each request now waits thirty seconds, threads fill up, and the whole site hangs even though only one feature was affected. A breaker returns a simple "estimate unavailable" message at once and keeps the rest alive.

Practical advice

  • Decide the fallback in advance: cached data, a default, or a clear message.
  • Pair it with timeouts and retries using backoff, not in place of them.
  • Alert when a breaker opens; it is a useful early signal. Libraries such as Resilience4j, Polly and Opossum provide ready-made versions.

Questions, answered

No. Retries try again; a breaker deliberately stops trying for a while to give the failing service room to recover.

Only where a slow third-party call could take down the whole app. Payment, mapping and email calls are typical candidates.

By the Stegnor team · Updated