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
In AI systems: Reliability: fallbacks, timeouts and guardrails
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.
- App — healthy
- Circuit breaker — healthy — closed
- Service — healthy
- Calls sent to the service
- not shown yet
- Calls failed fast
- not shown yet
- Calls pass through. While the breaker is closed, every call goes through it to the service as normal.
- Count the failures. It keeps the last 10 results, and once 5 calls have finished, it checks how many failed.
- Trip open. When 50% or more of them failed, the breaker opens and stops calling the service.
- Fail fast. While it is open, each call fails at once with a fallback answer, instead of waiting on a sick service.
- Test with a few. After 5 s it turns half-open and lets 3 trial calls through to test the service.
- Close again. If all 3 trials work, it closes again; in this lab, one failed trial opens it again.
- 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
- Closed: calls go through as normal, while the breaker counts how many recent calls failed.
- Open: once 50% or more fail, calls fail at once with a fallback, without calling the service.
- Half-open: after 5 s, a few trial calls test whether the service has recovered.
- Failing fast frees the caller and gives the sick service time to recover.
In plain words
Say an app calls a service through a (A switch that stops calls to a failing service for a while, so callers fail fast instead of waiting.). 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 (A simpler answer sent instead of the real one, used when a call is skipped or fails.), 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 (The time a caller waits before giving up on a call and treating it as failed.), 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 (One line of work inside a running program. A server runs many threads, so it can work on many requests at the same time.) 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
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.
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.
OPEN state (tripped)
Pick a case to follow belowWith 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 recommendations Product page calls recommendations Recommendations, the dependency, NOW Recommendations the dependency answers NOW - Product page — calls recommendations — healthy
- Recommendations — the dependency — healthy — NOW — answers
- Answer
- Timeout or refused
Step 1 of 3Step 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 100 of 10Breakernoneevery call is sentWait for the next call0sStep 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.
HALF-OPEN state (trial)
After a wait, such as 5 seconds, the breaker lets a few trial calls through. Everything else is still rejected.
Recovery or re-trip
Pick a case to follow belowWith this case: All 3 trial calls worked, so the breaker closed and traffic flows again.
Product page, calls recommendations Product page calls recommendations Circuit breaker, last 10 calls, NOW Circuit breaker last 10 calls open · 5 s NOW Recommendations, the dependency Recommendations the dependency Fallback, a default list Fallback a 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 3Step 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
BreakeropenWatch: calls skip the serviceTrial calls that worked0 of 3Step 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.
Bulkheads: a pool per dependency
Pick a case to follow belowWith this case: In one shared pool, all 100 threads ended up waiting on recommendations, and checkout stopped too.
Users, browse and pay Users browse and pay Web server, 100 threads Web server 100 threads 10 stuck Recommendations, the dependency, FAILED, NOW Recommendations the dependency hangs FAILED Checkout, healthy Checkout healthy - 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 3Step 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 recommendations10 of 100Threads left for checkout90checkout keeps workingCheckoutservedusers can payStep 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
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
Interview
What interviewers look for
- Name the three states and what each does: "Closed passes calls and counts failures. Open fails fast. (A circuit breaker state that lets a few trial calls through, to test whether a failing service has recovered.) 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 (A small, fast store that keeps copies of popular data, so most reads skip the slower database.)."
- 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?
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
Apply it
Judge a design
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.