Skip to content
Latchkey

What Is a Circuit Breaker? Explained

A circuit breaker is a resilience pattern that stops calling a failing dependency for a while, so the dependency can recover and callers fail fast instead of piling on.

When a dependency is down, retrying it over and over wastes resources and can deepen the outage. A circuit breaker, named after the electrical device, detects sustained failure and "trips", short-circuiting further calls until the dependency looks healthy again. It is a key counterpart to retries.

The three states

  • Closed: calls flow normally; failures are counted.
  • Open: too many failures tripped the breaker, so calls fail fast without trying.
  • Half-open: after a cooldown, a few trial calls test whether the dependency recovered.

Why it complements retries

Retries assume the failure is brief; a circuit breaker handles the case where it is not. If a dependency is genuinely down, retrying every call just adds load. The breaker trips, stops the futile calls, and lets the dependency recover, then cautiously probes before resuming.

Failing fast

When the breaker is open, calls return immediately with a clear failure rather than hanging on a timeout. That fast, predictable failure is often better than a slow one: it frees resources, avoids cascading slowdowns, and gives callers a clear signal to degrade gracefully.

Where it fits in CI

Circuit breakers matter most in services and integrations a pipeline calls, and conceptually in how you treat a persistently failing upstream: at some point you stop retrying and report a real incident. The pattern encodes the line between transient (retry) and sustained (trip and escalate).

The Latchkey angle

The principle behind a circuit breaker, retry the transient but do not hammer the broken, mirrors how good self-healing behaves. Latchkey self-healing managed runners retry transient and mechanical failures with sensible limits so a one-off blip does not fail your build, without endlessly retrying a sustained failure.

Key takeaways

  • A circuit breaker stops calling a failing dependency to let it recover.
  • Its states are closed, open, and half-open.
  • It complements retries by handling sustained, not brief, failures.
  • Failing fast when open frees resources and avoids cascades.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →