← Lessons

quiz vs the machine

Gold1430

System Design

The Circuit Breaker

Stop hammering a failing dependency so it can recover instead of dragging your whole service down.

4 min read · core · beat Gold to climb

Failing fast on purpose

A circuit breaker wraps calls to a remote dependency and stops sending requests once that dependency looks unhealthy. Borrowed from electrical engineering, it trips open to protect the rest of the system rather than letting failures pile up.

Without it, calls to a dead service keep waiting for timeouts, threads pile up, and a single sick dependency can stall every request in your service. This is how one slow service cascades into a full outage.

Three states

  • Closed is normal, requests flow and failures are counted.
  • Open trips after too many failures, and calls fail fast without even trying.
  • Half open lets a few trial requests through to test whether the dependency has recovered.

Why it helps

Failing fast frees up resources and gives the struggling dependency room to recover. Paired with a sensible fallback, such as a cached value or a default response, a circuit breaker keeps your service responsive even when something downstream is broken.

Key idea

A circuit breaker fails fast on a sick dependency so failures do not cascade and recovery can happen.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a circuit breaker do when it is open?

2. What is the purpose of the half open state?