← Lessons

quiz vs the machine

Platinum1860

Concurrency

The Circuit Breaker for Async

Stop calling a failing service and let it recover.

6 min read · advanced · beat Platinum to climb

Fail fast under sustained failure

A circuit breaker wraps calls to a dependency and trips open when failures pass a threshold. While open it rejects calls immediately instead of waiting on a service that is clearly down.

Three states

  • Closed: calls pass through and failures are counted.
  • Open: calls fail fast for a cool down period without touching the dependency.
  • Half open: a few trial calls are allowed to test recovery.

If the trial calls in half open succeed, the breaker closes again. If they fail, it returns to open and restarts the cool down.

Why it helps async systems

Failing fast frees threads and futures that would otherwise block on a dead dependency, which prevents the queue buildup a bulkhead also guards against. It also gives the struggling service breathing room by cutting traffic.

Tuning

Set the failure threshold from a rolling window of recent calls, not a single error. Keep the cool down long enough for real recovery but short enough to restore service quickly.

Key idea

A circuit breaker moves between closed, open, and half open to fail fast during outages and probe for recovery before resuming traffic.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a circuit breaker do in the open state?

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

3. How should the failure threshold be measured?