Stage 4 · Reliability · Medium · 18 min

Circuit breakers and bulkheads

Stop one failing dependency from taking down its callers. Learn the breaker's three states, closed, open and half-open, plus fallbacks and bulkheads.

What each interview level is expected to know

Learn first: Timeouts, retries and idempotency

After this lesson you can:

  • Explain the closed, open and half-open states of a circuit breaker.
  • Choose a fallback for when the breaker is open.
  • Use bulkheads so one slow dependency cannot use up every thread.

Start here

See it in 60 seconds

Closed, open, half-open

A circuit breaker stops calls to a failing service for a while, then tests it with a few calls before trusting it again.

Scene 1 of 6 · Calls pass through

While the breaker is closed, every call goes through it to the service as normal.

AppAppCircuit breakerCircuit breakerclosedServiceService
  • App — healthy
  • Circuit breaker — healthy — closed
  • Service — healthy
Calls sent to the service
not shown yet
Calls failed fast
not shown yet
  1. Calls pass through. While the breaker is closed, every call goes through it to the service as normal.
  2. Count the failures. It keeps the last 10 results, and once 5 calls have finished, it checks how many failed.
  3. Trip open. When 50% or more of them failed, the breaker opens and stops calling the service.
  4. Fail fast. While it is open, each call fails at once with a fallback answer, instead of waiting on a sick service.
  5. Test with a few. After 5 s it turns half-open and lets 3 trial calls through to test the service.
  6. Close again. If all 3 trials work, it closes again; in this lab, one failed trial opens it again.
  7. Now you try. Tap call results in order, and wait when you like. Watch the breaker change state. For example, tapping Call fails, Call fails, Call fails, Call fails, Call fails and Call works gives this: The breaker went closed → open; 5 calls reached the service and 1 failed fast. It is open now: calls fail fast until 5 s pass, which gives the service time to recover.

Scene 1 of 6: Calls pass through. While the breaker is closed, every call goes through it to the service as normal.

Key points

  1. Closed: calls go through as normal, while the breaker counts how many recent calls failed.
  2. Open: once 50% or more fail, calls fail at once with a fallback, without calling the service.
  3. Half-open: after 5 s, a few trial calls test whether the service has recovered.
  4. Failing fast frees the caller and gives the sick service time to recover.

Go deeper in the Circuit breaker lab →

In plain words

Say an app calls a service through a . The breaker remembers the last 10 results. While most calls work, it is closed and passes every call through. Then the service starts to fail. Once half or more of the recent calls have failed, the breaker opens. For the next 5 seconds it does not call the service at all. Each call fails at once, and the app shows a , such as a default list. After the 5 seconds it lets 3 trial calls through. If all 3 work, it closes again.

Three settings shape it: how many recent calls it counts, the failure share that opens it, and how long it stays open. Too eager, and one slow second cuts off a healthy service. Too slow, and callers keep waiting on a dead one. Each dependency gets its own breaker, so trouble in payments does not cut off search. Every call also needs a , or a call that hangs never counts as a failure.

The problem it solves

A slow dependency is worse than a dead one. Each call to it holds a until the timeout, such as 2 seconds. With enough traffic every thread is waiting, and the caller cannot serve anything else. The slow service also keeps getting calls, so it never gets a quiet moment to recover.

Why it matters

A product page may call ten services, and some matter more than others. If the recommendations service hangs, the page should still load and the buy button should still work. A circuit breaker makes the caller give up on a failing service quickly, and show something simpler in its place.

A worked example

A circuit breaker trips when 50% or more of the last 10 calls fail. If 6 of those 10 calls fail, that is 6 ÷ 10 = 60%, above the 50% limit, so the breaker opens for 5 seconds. After that wait, it lets 3 trial calls through: if all 3 succeed, the breaker closes and normal traffic resumes.

Think of it like…

Think of the breaker box in a house. When a faulty appliance draws too much current, the breaker trips and cuts that one circuit. The other rooms keep their power.

Where this analogy stops working

Cutting off one faulty part to protect the rest is the useful part. But a house breaker stays off until a person resets it. A software breaker tests the service by itself: after a wait it lets a few trial calls through. While it is open it also refuses calls that would have worked.

Try it

See it working

Live simulationOpen the full lab →

Lab · Reliability

Circuit breaker

Service A calls Service B. When B keeps failing, a circuit breaker in A stops calling it for a while and returns a fallback instead — protecting both services. Break B and watch the breaker move through its three states.

Try it

Lab time 3.0 s
timeout 1 swhen openUsers, 6 req/sUsers6 req/sService A, breaker closed, CLOSEDService Abreaker closed3 waiting on callsCLOSEDService B (dependency), healthyService B (dependency)healthyworking on 3Fallback, cached or default answerFallbackcached or default answer
  • Users — 6 req/s — healthy
  • Service A — breaker closed — healthy — CLOSED — 3 waiting on calls
  • Service B (dependency) — healthy — healthy — working on 3
  • Fallback — cached or default answer — healthy
  • Request
  • Response
  • Error / rejected
  • Fallback
Breaker
Closed
Healthy: calls pass through
Calls reaching B
6/s
B is working on
3
Failed
1
1 errors · 0 timeouts
Fallbacks
0
answered without calling B
wait
830 ms

Numbers add up:19 calls = 15 succeeded + 1 failed + 0 fallbacks + 3 in flightThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Service B
Health

Answers in ~200 ms. Occasional errors (2%).

Traffic
6/s
Breaker settings
50%
5 s
3

Breaker state

State machine
50%+ of last 10 failafter 5 sa trial fails3 trials succeedClosed● currentOpenfail fastHalf-opentrial calls
  1. 0.0s Closed — start
Calls reaching Service B per second (shaded: breaker open)
02.557.5101s2s3s
Show data table
TimeCalls to B/s
1s8
1s4
2s8
2s4
3s8
3s6

What just happened

Nothing yet. Start traffic or run an experiment.

What this model simplifies
  • The failure window counts the last 10 calls and needs at least 5 before it can trip. Libraries such as Resilience4j also offer time-based windows and slow-call thresholds.
  • One breaker for one dependency. Real services keep a separate breaker per downstream dependency (and sometimes per endpoint).
  • The fallback always succeeds. In practice a fallback can be stale, partial, or unavailable too — design what users see when it is.

Also try: Retries, backoff & jitter

Mechanics

How it works

The pictures follow this page's example: a product page calls recommendations through a breaker that watches the last 10 calls. The first two show the breaker opening and closing. The last shows a bulkhead on a server with 100 threads.

  1. CLOSED state (normal)

    A circuit breaker wraps calls to one dependency. While it is closed, calls pass through and the breaker counts how many fail. For example, it tracks the failure rate over the last 10 calls.

  2. OPEN state (tripped)

    Pick a case to follow below

    With this case: With no breaker, every call to the failing service waits the full 2-second timeout, and the service never gets a rest.

    Product page, calls recommendationsProduct pagecalls recommendationsRecommendations, the dependency, NOWRecommendationsthe dependencyanswersNOW
    • Product page — calls recommendations — healthy
    • Recommendations — the dependency — healthy — NOW — answers
    • Answer
    • Timeout or refused
    Step 1 of 3

    Step 1 of 3 · Recommendations

    Done: The first 5 calls work

    What happens
    Each call goes to recommendations and comes back.
    Why
    Nothing is wrong yet.
    What changes
    0 of the last 10 calls failed.
    Next
    The next 5 calls each time out after 2 seconds
    Failed of last 10
    0 of 10
    Breaker
    none
    every call is sent
    Wait for the next call
    0s

    Step 1 of 3: Recommendations. The first 5 calls work. Each call goes to recommendations and comes back.

    If failures reach a threshold, such as 50%, the breaker opens. Now it rejects calls at once, without contacting the dependency. The caller returns a fallback, such as a cached answer, and the failing service gets time to recover.

    In the picture, 5 calls work, and then the next 5 time out after 2 seconds each. That is 5 of the last 10 failed, which reaches 50%, so the breaker opens.

    The next call gets the default list in 0 seconds. With no breaker, it would wait another 2 seconds and fail, and the struggling service would get no rest.

  3. HALF-OPEN state (trial)

    After a wait, such as 5 seconds, the breaker lets a few trial calls through. Everything else is still rejected.

  4. Recovery or re-trip

    Pick a case to follow below

    With this case: All 3 trial calls worked, so the breaker closed and traffic flows again.

    Product page, calls recommendationsProduct pagecalls recommendationsCircuit breaker, last 10 calls, NOWCircuit breakerlast 10 callsopen · 5 sNOWRecommendations, the dependencyRecommendationsthe dependencyFallback, a default listFallbacka default list
    • Product page — calls recommendations — healthy
    • Circuit breaker — last 10 calls — healthy — NOW — open · 5 s
    • Recommendations — the dependency — healthy
    • Fallback — a default list — healthy
    • Answer
    • Call
    Step 1 of 3

    Step 1 of 3 · Circuit breaker

    Watch: The breaker waits 5 seconds

    What happens
    Every call in this time gets the fallback.
    Why
    The service needs a quiet moment to recover.
    What changes
    At the end of the wait, the breaker turns half-open.
    Next
    All 3 trial calls work
    Breaker
    open
    Watch: calls skip the service
    Trial calls that worked
    0 of 3

    Step 1 of 3: Circuit breaker. The breaker waits 5 seconds. Every call in this time gets the fallback.

    If the trial calls succeed, the breaker closes and traffic flows again. If they fail, it opens for another wait.

    In the picture, the breaker waits 5 seconds, then sends 3 trial calls. If all 3 work, it closes. If they fail, it opens for another 5 seconds, and only those 3 calls reached the failing service.

  5. Bulkheads: a pool per dependency

    Pick a case to follow below

    With this case: In one shared pool, all 100 threads ended up waiting on recommendations, and checkout stopped too.

    Users, browse and payUsersbrowse and payWeb server, 100 threadsWeb server100 threads10 stuckRecommendations, the dependency, FAILED, NOWRecommendationsthe dependencyhangsFAILEDCheckout, healthyCheckouthealthy
    • Users — browse and pay — healthy
    • Web server — 100 threads — healthy — 10 stuck
    • Recommendations — the dependency — FAILED — NOW — hangs
    • Checkout — healthy — healthy
    • Call
    • Timeout or refused
    Step 1 of 3

    Step 1 of 3 · Recommendations

    Watch: Recommendations hangs, and 10 threads wait on it

    What happens
    10 calls to recommendations get no answer. Each one holds a thread.
    Why
    A hung call keeps its thread until the call ends.
    What changes
    90 threads are still free.
    Next
    All 100 threads end up waiting on recommendations
    Threads stuck on recommendations
    10 of 100
    Threads left for checkout
    90
    checkout keeps working
    Checkout
    served
    users can pay

    Step 1 of 3: Recommendations. Recommendations hangs, and 10 threads wait on it. 10 calls to recommendations get no answer. Each one holds a thread.

    What these pictures simplify. These pictures use stated results and round times. Real breakers often count failures over a time window, such as the last 10 seconds, and set how many trial calls to send. The circuit breaker lab above runs many calls through one.

    A bulkhead gives each dependency its own limited pool of threads or connections. Say the server has 100 threads and the recommendations service may use 10 of them. If that service hangs, 10 threads are stuck and the other 90 keep serving checkout. A breaker stops the calls, and a bulkhead limits the damage before the breaker opens.

    In the picture, recommendations hangs. In one shared pool, each page view adds a stuck thread until all 100 are waiting, and checkout cannot answer either.

    With a pool of 10, the 11th call to recommendations is refused at once. The other 90 threads keep serving checkout.

Use it when

  • A call to another service or an outside API that can hang: the breaker keeps the caller fast while the other side recovers.
  • A feature the page can live without, such as recommendations, ratings or comments: show a default or leave the section empty.
  • Several dependencies sharing one server: give each its own pool, a bulkhead, so one slow dependency cannot use every thread.

Skip it when

  • A plain function call inside the same program: there is no remote service to protect, so a breaker only adds code.
  • A call with no fallback, if you expect the breaker to hide the failure: it only turns a slow error into a fast one.
  • A dependency with very little traffic: a few calls are too small a sample, so one failure could open the breaker.

Check yourself

What does a circuit breaker do in its half-open state?

Judgement

Trade-offs and how it fails

What you give up

Resilience
The caller stays fast when a dependency fails, because calls fail at once and do not wait for a timeout. The failing service also gets a pause in traffic.
Complexity
Someone must choose the threshold, the wait and the number of trial calls, and write a fallback for each call. Set too sensitive, the breaker opens on a brief blip. Set too loose, it opens after the damage is done.
Quality
While the breaker is open, users get the fallback: a default list, an old cached value or a missing section. That is less than the real answer, and for some data an old value is wrong.

Failure modes

  • A breaker that flaps: the threshold is too sensitive, so it opens on a one-second blip, closes, and opens again. Require a minimum number of calls before it may open.
  • No fallback: the breaker opens and the caller gets an error it does not handle. The page fails anyway, only faster.
  • One breaker for everything: all calls to a service share a breaker, and one broken endpoint opens it for the healthy ones too. Use a breaker per endpoint or per kind of call.

In the real world

  • Netflix's Hystrix library wraps each call to a dependency in a circuit breaker, a separate thread pool and a fallback. In 2018 Netflix put it in maintenance mode and pointed new projects to Resilience4j. Source: Netflix Hystrix on GitHub (checked 14 October 2026)
  • Michael Nygard's book "Release It!", first published in 2007, described the circuit breaker and bulkhead patterns for software. Source: Pragmatic Bookshelf: "Release It!", second edition (checked 14 October 2026)
  • Resilience4j's documentation lists the same three states, CLOSED, OPEN and HALF_OPEN. It counts failures over a sliding window of recent calls. Source: Resilience4j docs: CircuitBreaker (checked 14 October 2026)

Trade-offs to be ready to discuss: Circuit breaker thresholds

Check yourself

What is the bulkhead pattern?

Interview

What interviewers look for

  • Name the three states and what each does: "Closed passes calls and counts failures. Open fails fast. sends a few trial calls."
  • Add bulkheads: "Each dependency gets its own thread pool, so one slow service cannot take every thread."
  • Say what the user sees while the breaker is open: "If recommendations are down, the page shows best-sellers from a ."
  • Put the pieces in order: "A timeout bounds each call and a retry covers a brief fault. The breaker stops the retries when the fault lasts."

Say it out loud: What are the three states of a circuit breaker, and what happens in each?

The recommendation service is timing out, and every product page waits 2 seconds for it. A circuit breaker opens. What do users see now?

Expected depth by interview level

Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.

JuniorUseful
Stop calling a service that keeps failing.
MidExpected
Breaker states and fallbacks.
SeniorCore
Breakers, bulkheads and graceful degradation together.
StaffExpected
Failure isolation across a platform.

Practice

Apply it

Three harder questions

The first two use the idea on a new case. The last asks you to judge a design.

Apply it

A breaker is open for 5 seconds. In that time the app makes 200 calls to the service behind it. How many reach the service?

Apply it

A server has 200 threads. A bulkhead lets the search service use at most 30. Search hangs. How many threads can still serve checkout?

Judge a design

All calls to the user service share one breaker. Only the avatar endpoint is broken, and it makes 60% of the calls. What happens, and what is better?

Next: cascading failures, how one slow service can take down everything that calls it.

Go deeper

Sources and further reading

First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.

  • Engineering guideCircuitBreakerMartin FowlerThe closed, open and half-open states, with a small code example.
  • Official docsCircuitBreakerResilience4j documentationA real library’s settings: failure-rate threshold, window size, wait time in the open state.
  • Engineering guideBulkhead patternMicrosoft Azure Architecture CenterSplitting threads or connections into pools so one slow dependency cannot use them all.