Designbench

Lesson 5.2 · 15 min

Circuit breakers

Break a dependency for 20 seconds and watch a shared thread pool drain, then add a circuit breaker and a bulkhead and replay the same minute.

The idea in plain words

A circuit breaker in your house cuts power when something shorts, before the wires catch fire. In software it stops calling a failing service for a while, so your own servers don’t get stuck waiting and the other service gets time to recover.

The problem it solves

When a service you depend on is down or very slow, every call to it waits until it times out. Your threads fill up with waiting calls and your service fails too, even for features that don’t need the broken one.

How it works

  1. Wrap calls to the dependency and count recent failures.
  2. If failures pass a threshold, the breaker opens: calls fail immediately without being sent.
  3. Return a fallback instead: cached data, a default, or a clear error.
  4. After a pause, let a few test calls through (half-open).
  5. If they succeed, close the breaker and resume; if not, open it again.

Example

The recommendations service hangs. Without a breaker, product pages wait 10 s for it and the whole site slows. With one, after a few failures pages skip recommendations instantly and load in 200 ms; when the service recovers, recommendations come back on their own.

Key terms

Closed
Normal: calls go through and failures are counted.
Open
Too many failures: calls fail immediately without being sent.
Half-open
After a pause, a few test calls go through to see if the service is back.
Fallback
What you return instead: cached data, a default, or a clear error.
Bulkhead
Separate thread pools per dependency, so one slow service can’t use them all.

In this lesson you'll learn

Sections

  1. Theory: a dependency hangs
  2. Theory: compare protections
  3. Design: pick a fallback
  4. Check yourself

Cheat sheet

Closedcalls flow; count failures
Openfail fast for a cool-down
Half-opena few probes decide
Bulkheadseparate pool per dependency
Threads neededrate × time each call is held

The interactive simulations and the quiz load with JavaScript.