← Lessons

quiz vs the machine

Gold1460

Concurrency

The Circuit Breaker For Concurrency

Trip open on failures so concurrent callers stop hammering a sick service.

5 min read · core · beat Gold to climb

The Circuit Breaker For Concurrency

A circuit breaker protects a system when a downstream dependency starts failing. Instead of letting every concurrent caller keep waiting on a sick service and exhausting threads, the breaker detects trouble and fails fast for a while.

The breaker is a state machine with three states:

  • Closed Calls pass through normally. The breaker counts failures.
  • Open After failures cross a threshold, the breaker trips. Calls fail immediately without touching the dependency, freeing threads.
  • Half open After a cooldown the breaker lets a few trial calls through. If they succeed it closes; if they fail it opens again.

This matters under concurrency because a slow dependency otherwise causes thread exhaustion. Hundreds of requests block waiting, the pool drains, and unrelated features stall. By failing fast, the breaker bounds the damage and gives the dependency room to recover rather than being hammered while it is down.

Tuning involves the failure threshold, the rolling window for counting, and the cooldown before probing. Pair the breaker with a sensible fallback, such as a cached value or a degraded response, so callers get something useful instead of an error.

Key idea

A circuit breaker fails fast when a dependency is unhealthy, preventing concurrent callers from exhausting threads while it recovers.

Check yourself

Answer to earn rating on the learn ladder.

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

2. What concurrency failure does a circuit breaker primarily prevent?