Distributed systems · L2Circuit breakers, bulkheads and fallbacks

Circuit breakers, bulkheads and fallbacks

One slow service can take down every service that calls it. Here is how to keep the damage small.

L2 SeniorDistributed systems21 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 9 Nov 2026 · How we check content
Section 1 of 8

What broke

On 12 June 2025, Cloudflare's Workers KV started to fail. KV is a key-value store, and Cloudflare calls it "a critical dependency for many Cloudflare products". 1

Part of the storage behind KV ran on a third-party cloud, and that cloud had its own outage. About 90% of KV requests failed. Reads that hit a cache still worked. 1

The failure did not stay inside KV. Access, Cloudflare's login gate, failed every identity-based login. Dashboard logins failed, and Workers AI could not run models at all. 1 Cloudflare wrote that the cascading impact from KV "significantly broadened the blast radius." 1

Each product's design decided what happened when KV failed. Access and Gateway are designed to fail closed, so they blocked users instead of skipping customer rules. Turnstile turned on kill switches that switch off those failing calls. Users could get through, but a token could be used more than once. 1

At 19:32 UTC, Access and Device Posture dropped requests on purpose to take load off KV. Impact ended at 20:28 UTC. One fix is a tool to bring KV back step by step, without "a denial-of-service against our own infrastructure as caches are repopulated." 1

Section 2 of 8

The idea in simple words

Every service you call can fail or get slow. If you do nothing, its problem becomes your problem, and then your callers' problem.

Four tools keep the damage small:

  • A timeout limits how long one call waits.
  • A circuit breaker stops calling a service that keeps failing, for a short time.
  • A bulkhead limits how many of your threads one dependency can use.
  • Graceful degradation decides what the user gets when the call fails: old data, a default, or a page without that feature.

The key idea. A dead dependency fails fast. A slow one holds on to your threads until you have none left. Put a limit on every call: how long it waits, how many calls wait at once, and how long you keep calling a service that is failing.

Section 3 of 8

How it works

Why slow is worse than dead

If a service is down and its machine refuses the connection, you get an error in milliseconds. (If the whole machine is gone, you wait for the connect timeout.) If it is slow, each call holds memory, a thread and a connection while it waits. 8

New requests keep coming, so waiting calls pile up. Say you get 200 requests a second and each makes one call. At 50 ms per call, about 10 calls wait at any moment. At 5 seconds per call, about 1,000 wait. A pool of 200 threads is full in about one second.

The Hystrix wiki says that under high traffic, "a single backend dependency becoming latent can cause all resources to become saturated in seconds on all servers." 3 Now your service is slow too, and your callers start to pile up. Fowler calls the result "cascading failures across multiple systems." 2

Timeouts come first

You met timeouts in Idempotency and retries. Every remote call needs one. Amazon picks an acceptable rate of false timeouts, such as 0.1%. It then uses that percentile of the downstream latency: the 99.9th percentile. 8

A timeout caps one call. It does not stop you from sending the next call to the same slow service, and the one after that. That is the job of the circuit breaker.

The circuit breaker

Michael Nygard made this pattern popular in his book Release It!. Martin Fowler's short article describes it well. 2 You wrap the remote call in a breaker object that watches for failures. It has three states:

  • Closed. Calls go through. The breaker counts failures, and a timeout counts as a failure. 2
  • Open. When failures reach a threshold, the breaker trips. Every call now gets an error at once, and the service is not called at all. 2
  • Half-open. After a wait, the breaker lets a trial call through. If it works, the breaker closes. If it fails, the breaker opens and waits again. 2

Step through a breaker in front of a ratings service. Use Next and Back, or the ← and → keys.

A circuit breaker in front of a ratings service: closed, open, half-open, closed againShop API → breaker → Ratings service example: open at 50% failures of the last 20 calls CLOSEDcall → 200 OK, 40 msevery call goes throughthe breaker counts results CLOSEDcall → no answer in 1 s12 of last 20 failed = 60%60% ≥ 50%, so it trips OPENerror at onceno call is sent · page hides ratingswait 30 s HALF-OPEN3 trial callsother calls still get an error3 of 3 trial calls work CLOSEDnormal traffic againratings are back on the pagecounting starts again SeniorPath
  1. Closed is the normal state. Every call from the Shop API goes through to the Ratings service. The breaker records whether each call worked.
  2. The Ratings service gets slow. Calls hit their 1-second timeout, and each timeout counts as a failure. When 12 of the last 20 calls have failed, the failure rate is 60%. That is over the 50% threshold, so the breaker trips.
  3. Open: the breaker returns an error at once, without calling the service. The Shop API's threads are free again, and the slow service gets no new load. The page shows without ratings. The breaker waits 30 seconds.
  4. Half-open: after the wait, the breaker lets 3 trial calls through. All 3 work. If they had failed, the breaker would go back to open and wait again.
  5. Closed again: all calls go through, and the breaker starts counting from fresh. These numbers are an example. Pick yours from your own traffic.
Step 1 of 5

Real libraries judge a rate, not a simple count. Hystrix trips only when there are enough requests and the error percentage is over a threshold. After a sleep window, it lets one request through as a test. 4

Resilience4j records the last N calls, or the calls in the last N seconds. It can also trip when too many calls are slow, not only when they fail. That matters, because slow is the dangerous case. An open breaker rejects calls with a CallNotPermittedException. 6 Here is the diagram's setup in Resilience4j. The slow-call setting does not stop a call, so you still need the timeout:

// The 1 s timeout is set on the HTTP client (or a TimeLimiter).
// The breaker counts the timeout exception as a failure.
CircuitBreakerConfig config = CircuitBreakerConfig.custom()
    .slidingWindowType(SlidingWindowType.COUNT_BASED)
    .slidingWindowSize(20)              // judge the last 20 calls
    .minimumNumberOfCalls(10)           // but only after 10 calls
    .failureRateThreshold(50)           // open at 50% failures
    .slowCallDurationThreshold(Duration.ofSeconds(1))
    .slowCallRateThreshold(50)          // or at 50% slow calls
    .waitDurationInOpenState(Duration.ofSeconds(30))
    .permittedNumberOfCallsInHalfOpenState(3)
    .build();

The defaults are larger: a window of 100 calls, at least 100 calls before it judges, a 60-second wait and 10 trial calls. A call counts as slow only after 60 seconds, and the breaker trips on slow calls only if all of them are slow. 6 So set both slow-call values yourself. Check them against your traffic. A breaker that needs 100 calls may never trip on a quiet endpoint.

Log every state change, and show the breaker's state on your monitoring. 2

Breakers have a cost, as you saw in Error handling. They add a second mode of working, which "can be difficult to test", and they can slow recovery. 8 Amazon limits retries locally instead, as in Backoff, jitter and retry budgets. 8

Bulkheads

A ship's hull is split into sealed sections. If one section floods, the others keep the ship afloat. A bulkhead in software does the same for your threads.

Give each dependency its own small pool. Hystrix ran a separate thread pool per dependency, so a slow dependency filled only its own pool. 4 Each Netflix API server had more than 40 thread pools, with 5 to 20 threads each, and most had 10. 4

A lighter option is a semaphore: a counter of calls in flight. It costs less than a thread pool. But the caller cannot time out and walk away from a call that hangs. 4 Resilience4j offers both kinds. Its semaphore bulkhead allows 25 calls at once by default, and it does not wait for a free slot. 7

Here is the effect. Your service has 200 threads, and the ratings call gets a bulkhead of 20. When ratings gets slow, 20 calls wait and the 21st is rejected at once. The other 180 threads keep serving other pages, such as checkout.

Fallbacks and graceful degradation

When a call fails, you still have to send the user something. Serving less instead of failing is graceful degradation. Common choices:

  • Stale data. Show the last cached ratings.
  • A default. Show a safe value from config, such as the standard delivery time.
  • Hide the feature. Show the product page without ratings.
  • Fail. Return a clear error. Cloudflare's Access chose this on purpose, to avoid letting in users it could not check. 1

Hystrix calls code like the first three a fallback. Its advice: a fallback should avoid network calls, and "It is a poor practice to implement a fallback implementation that can fail." 4

Amazon uses the word fallback in a narrower sense: a different mechanism that does the same job. Its example is web servers that read from a database when their cache fails. Amazon almost never uses that kind, because it rarely runs, is hard to test and can make an outage worse. 9 Error handling tells the story of the outage behind this view.

Amazon prefers to make the main path more reliable. Two of its other options: push data out ahead of time, as when EC2 instances get IAM role credentials that stay valid for hours. Or run both paths all the time, for example by picking at random between their answers, so neither path is rare. 9

Amazon's warning is about a second mechanism for the same job. The same logic applies to any degraded mode, though: code that rarely runs needs tests.

The Turnstile kill switch shows the trade: users kept moving, but tokens could be reused. 1 Decide each trade with your product owner before the outage.

Where these live

  • In your code, as a library. Resilience4j is one Java library for this. Hystrix is in maintenance mode, and Netflix suggests resilience4j for new projects. 5
  • In a proxy next to each service, as in a service mesh. Envoy calls its per-cluster limits "circuit breaking": maximum connections, pending requests, requests and active retries. 10 These act like bulkheads, and you write no app code. Removing hosts that fail more than their peers is a separate Envoy feature, outlier detection. 11
  • At the gateway, to guard your services from outside traffic.

The server can protect itself too, by rejecting work it cannot finish in time. That is load shedding, the topic of load shedding and graceful degradation.

Test them

A breaker or fallback that never ran is like any rare code path: it may not work. Make a dependency slow in a test environment. Check that the breaker opens, the bulkhead rejects and the page still renders. Chaos engineering and game days shows how to do this safely in production.

Section 4 of 8

Trade-offs

OptionProtects your threads?CostUse it when
Timeout onlyPartly. Each call is capped, but slow calls still pile up.Almost nothing.Always. It is the minimum.
Circuit breakerYes An open breaker fails fast.A new mode that is hard to test. It can slow recovery.A dependency fails or slows for minutes, not milliseconds.
Thread-pool bulkheadYes Each dependency has its own pool.More threads and a thread switch on each call.Blocking calls to several dependencies of different health.
Semaphore bulkheadYes , it caps calls in flight.You cannot walk away from a hung call.Non-blocking clients, or calls with their own timeout.
Stale data or a defaultYes , if it needs no network call.Users may see old or wrong data.Old data is clearly better than none.
Hide the featureYes Users lose that part of the page.The feature is optional.
Fail closed with an errorYes Users are blocked.Security checks, payments, anything unsafe to guess.

Simple rule: a timeout on every call, a bulkhead per dependency, a breaker where failures last, and a fallback only if you test it often.

Section 5 of 8

At work: how a senior uses this

  • List every dependency of your service. For each one, ask: "If this takes 10 seconds, what happens to our threads?"
  • Mark each dependency as critical or optional. Optional ones get a bulkhead and a planned degraded mode.
  • Size bulkheads with numbers: calls a second × normal latency, plus room for spikes.
  • Put breaker state on a dashboard and alert when a breaker stays open.
  • Agree with the product owner on fail open or fail closed, feature by feature.
Section 6 of 8

With AI

What to ask the agent

"List every outgoing call in this service. For each, show the timeout, retry policy, circuit breaker and bulkhead settings, and what the caller gets on failure. Mark calls with none."

"Wrap the ratings client in a Resilience4j circuit breaker and a semaphore bulkhead of 20 calls. On CallNotPermittedException or BulkheadFullException, return an empty ratings list. Do not make network calls in the fallback."

"Write a test where the ratings service answers after 5 seconds. Assert that the breaker opens, that checkout still answers in under 300 ms, and that the page renders without ratings."

What to check yourself

  • Every remote call has a timeout, and the breaker counts a timeout as a failure.
  • Thresholds fit your real traffic, not the library defaults.
  • No fallback calls another remote service, especially a shared database.
  • Fail open or fail closed was a decision, not an accident.
  • A test makes the dependency slow, not just down.
Section 7 of 8

Check yourself

1. Service A calls service B. Which version of B hurts service A more?

Show answer

B is up but answers every call after 10 seconds. A refused call fails in milliseconds. A slow call holds a thread and a connection while it waits, so waiting calls pile up and use up A's threads.

2. A circuit breaker is open. Your code makes a call through it. What happens?

Show answer

The breaker returns an error at once, without calling the service. An open breaker fails fast. That frees your threads and gives the failing service a rest.

3. The breaker is half-open, and its trial calls fail. What does it do next?

Show answer

It goes back to open and waits again. Failed trial calls mean the service is still sick. The breaker opens again and starts a new wait.

4. Your service has 200 worker threads. Why give the ratings call its own pool of 20 slots?

Show answer

So a slow ratings service can tie up at most 20 threads, and the other 180 keep serving. That is a bulkhead. One bad dependency can fill only its own pool.

5. In the Builders' Library, what is Amazon's position on fallback, meaning a different mechanism that does the same job?

Show answer

Almost never use it. Make the main path more reliable, or run both paths all the time. A second mechanism that rarely runs is hard to test and can make an outage worse. Amazon prefers paths that run all the time.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 11 sources and related lessons
  1. Cloudflare blog, “Cloudflare service outage June 12, 2025” (opens in a new tab)
    The official report. See how one storage failure spread to Access, WARP, the dashboard and more, and how each product reacted.
  2. Martin Fowler, “Circuit Breaker”, martinfowler.com bliki (6 March 2014) (opens in a new tab)
    The closed, open and half-open states, with short Ruby code and advice on monitoring.
  3. Netflix/Hystrix wiki, “Home” (GitHub) (opens in a new tab)
    Why one slow dependency can use up all resources on every server in seconds.
  4. Netflix/Hystrix wiki, “How it Works” (GitHub) (opens in a new tab)
    Thread pools per dependency, semaphores, when the breaker trips, and rules for fallbacks.
  5. Netflix/Hystrix, README (GitHub) (opens in a new tab)
    Hystrix is in maintenance mode, and Netflix points new projects to resilience4j.
  6. Resilience4j documentation, “CircuitBreaker” (opens in a new tab)
    Sliding windows, failure and slow-call thresholds, every setting with its default, and a config example.
  7. Resilience4j documentation, “Bulkhead” (opens in a new tab)
    Semaphore and thread-pool bulkheads, with their settings and defaults.
  8. Marc Brooker, “Timeouts, retries, and backoff with jitter”, Amazon Builders' Library (opens in a new tab)
    What a waiting call holds on to, how Amazon picks a timeout, and the cost of circuit breakers.
  9. Jacob Gabrielson, “Avoiding fallback in distributed systems”, Amazon Builders' Library (opens in a new tab)
    Why Amazon usually avoids fallback, and what it does instead.
  10. Envoy documentation, “Circuit breaking” (architecture overview) (opens in a new tab)
    The per-cluster limits a proxy can enforce for you, with no app code.
  11. Envoy documentation, “Outlier detection” (architecture overview) (opens in a new tab)
    How Envoy finds hosts that fail more than their peers and removes them from load balancing.

Real incident: Cloudflare, 12 Jun 2025: Cloudflare outage: a storage provider failure broke many products

Case studies: Amazon: Timeouts, retries and backoff with jitter done right · Shopify: Ten habits for building payment systems that hold up · Uber: Retry topics and dead-letter queues with Kafka

Related: Idempotency, retries and timeouts · Backoff, jitter and retry budgets · Error handling and defensive design · Tail latency and queueing · API gateways and edge concerns · Why distributed systems are hard

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper