Why you are doing this at all
These three are usually taught as three separate tricks. A circuit breaker stops calling a service that is failing. A bulkhead keeps resources apart, so one part of the system can't use up what another part needs. Backpressure slows down whoever is sending the work. You learn three definitions separately, and none of them tells you when to use which.
In fact they're three answers to one question. What does your system do when more work arrives than it can serve?
Every system already has an answer to that, including yours, even if nobody chose it. The default answer is to queue. An unbounded thread pool queues. So does a connection pool with a long wait, and so does a message queue with no limit on its length, which is how a RabbitMQ queue starts out. Nobody had to set them up to do it.
Queueing is the worst answer available. A queue doesn't reduce load, it stores it. Latency climbs until requests time out at the client. The client retries, which adds more work, and the request you queued belongs to somebody who has already left. In the end you spend all your capacity on responses nobody is waiting for.
So this topic comes down to one point. Under overload, your system will do something. If you don't choose what, it collapses.
The one law that explains all three
The law is Little's Law. It holds for any stable system, meaning one that, over time, finishes work as fast as the work arrives:
L = λ x W
concurrency = arrival rate x time in system
That one line explains the whole article. L is the concurrency: how many requests are in progress at once. Your service has a fixed number of slots for them, and something finite sets that number: threads, connections, goroutines or file descriptors. That fixed number of slots is your pool.
Your users set λ, the arrival rate. Your slowest dependency sets W, the time each request spends in your system. So when a dependency slows down, W rises, and L rises with it. Once L passes the size of your pool, every slot is taken and the service stops answering anything at all.
Look at which failure caused that. If a dependency returns errors quickly, the damage is small. W stays small, the slots free up, and you serve an error and move on. A dependency that goes slow is the one that takes you down, because each call to it holds a slot and doesn't let go.
A service with 200 worker threads.
Healthy:
arrival rate λ = 1,000 req/s
service time W = 50 ms
⇒ concurrency L = 1,000 x 0.05 = 50 threads
pool of 200, so 150 spare. Comfortable.
Now one dependency degrades from 50 ms to 2 s.
Not down. Just slow.
arrival rate λ = 1,000 req/s (users have not changed)
service time W = 2 s
⇒ demanded L = 1,000 x 2 = 2,000 threads
pool of 200
⇒ 10x oversubscribed
What actually happens then:
throughput = pool / W = 200 / 2 = 100 req/s
⇒ capacity fell from 4,000/s (200 / 0.05) to 100/s
⇒ of the 1,000 req/s arriving, 900 now queue or fail
⇒ and the user gives up after 1 s, so even the
100/s that complete arrive after nobody is waiting
The dependency got 40x slower.
Your service's capacity fell 40x.
Nothing about your service changed.Everything below follows from that worksheet. You don't control λ, and you don't control W. You control what happens when λ times W is bigger than your pool, and that's the job of these three mechanisms.
When to skip this
If you have one service, one database and a few hundred requests a second, breakers everywhere add code and protect nothing. Set the timeouts, cap the pool, and move on.
The mechanisms are worth adding in three cases. The first is when you call something you don't run yourself. The second is when one dependency is slower or less reliable than the rest. The third is when one caller can use up capacity that other callers paid for. Outside those cases, the arithmetic above never gets large enough to matter.
The toolkit
The four mechanisms, and which variable each one attacks
With Little's Law in hand, the mechanisms are easy to sort, because each one works on a different term of the equation. They also sit in different places on a request's path.
| mechanism | which term | what it does | what it costs |
|---|---|---|---|
| timeout | caps W | gives up after a fixed time | some requests fail that would have succeeded |
| circuit breaker | drops W to ~0 | stops calling a dependency that is failing | requests fail fast during the open period, including ones that would have worked |
| bulkhead | caps L per dependency | one dependency cannot take the whole pool | you cannot burst into unused capacity |
| backpressure | reduces λ | refuses or sheds work before it enters | some users are turned away, deliberately |
Timeouts come first, and they're not optional. Without a timeout, a circuit breaker never trips, because nothing is ever recorded as a failure. The call hasn't failed. It's still waiting. A bulkhead without a timeout fills up and stays full. So the most common cause of this whole family of failures isn't a missing breaker. It's a missing deadline, a limit on how long a call may take.
Timeouts, and the part everyone gets wrong
A timeout is a number, and a badly chosen one can be worse than none at all.
Set it from the latency distribution, not from a round number. The p99 is the latency that 99 calls in 100 beat, and the p99.9 is the latency that 999 in 1,000 beat. If you set the timeout at the p99.9 of healthy latency, it fails only 1 healthy call in 1,000. A round number can land anywhere. A one second timeout on a call whose p99 is 1.2 seconds fails more than 1 healthy call in 100, all day, every day.
Deadlines must propagate, not repeat. Propagating a deadline means passing the time that's left down with each call. Say a request has a 300 ms budget and calls three services one after another. Each call can't have its own 300 ms timeout, because together they could take 900 ms. Instead, you pass the remaining budget down. The first call gets 300 ms. If it takes 120 ms, the second call gets 180 ms. Without this, the caller has already given up while three services further down keep working for it, and that's capacity spent on nobody.
A connection timeout and a read timeout are different numbers. Connecting should take milliseconds, while reading a response can reasonably take a second. If you use one value for both, either reads time out far too easily, or a connection to a host that silently drops every packet hangs for a long time.
Circuit breakers, precisely
A circuit breaker is a small state machine wrapped around the calls to one dependency. It has three states.
Closed. Calls pass through as normal. The breaker records each outcome in a rolling window, such as the last 30 seconds. When the failure rate crosses a threshold, the breaker trips to open.
Open. Calls fail immediately, without touching the dependency. This is the whole point of the breaker. W drops to microseconds, so L drops close to zero, and your pool is free again. After a cooldown, a fixed wait, the breaker moves to half-open.
Half-open. The breaker lets a small, fixed number of trial calls through. If they all succeed, it closes. If any fails, it goes back to open, usually with a longer cooldown.
A breaker has four settings. Teams usually get three of them wrong.
- Failure threshold, as a rate, not a count. For example, 50 percent of calls in the last 30 seconds.
- Minimum call volume before it can trip. Without it, one failed call out of one is a 100 percent failure rate, and your breaker opens on a quiet Sunday.
- Cooldown before half-open. If it's too short, you keep calling a dependency that is still down. If it's too long, you keep failing calls after the dependency has recovered.
- Half-open concurrency. This is the one people forget. If full traffic goes through the moment the cooldown ends, the recovering dependency is overloaded and fails again straight away. Allow one probe, or a few. A probe is a trial call.
Bulkheads
The name comes from ships. A ship's hull is split into sealed compartments, the bulkheads, so if one compartment floods, the ship still floats. In software, a bulkhead is a separate, capped pool of resources for each dependency or each tenant. A tenant is one customer that shares your system with others. If one pool runs out, the others still have theirs.
| type | how it caps | when to use |
|---|---|---|
| separate thread pools | each dependency gets its own workers | strong isolation, but a thread per call is expensive |
| semaphore or permit limit | a counter capping in-flight calls per dependency | cheap, and the usual choice in async code |
| separate connection pools | per downstream, sized independently | anywhere pooled connections are the scarce thing |
| per-tenant limits | a cap per customer within a shared pool | multi-tenant systems, so one tenant cannot eat the rest |
| separate instances | different machines serve different traffic | the strongest form, and the most expensive |
The size comes from Little's Law again. Set a bulkhead's limit to the concurrency you expect at healthy latency, plus some headroom. At 1,000 requests a second and 50 ms each, the healthy concurrency is 50. A limit of 75 leaves room for normal variation and refuses every call past it. If you set the limit to 500, it does nothing, because your pool of 200 runs out long before the bulkhead reaches its limit.
A bulkhead also stops a dependency from borrowing capacity that another one isn't using. You give up some utilisation to get isolation, and you do it on purpose.
Backpressure and load shedding
Backpressure means pushing back on whoever is sending the work, by refusing it or slowing it down before it enters. It's the only mechanism that changes λ. Everything else limits the damage from load you've already accepted. Load shedding is its simplest form: dropping some requests on purpose so the rest can be served.
Reject rather than queue. A fast 503, the HTTP status for "service unavailable", is a better answer than a slow success that nobody is waiting for. With a 503, the client can retry, try somewhere else, or show something simpler. A queued request that finishes after the caller has given up is pure waste.
Bound every queue. An unbounded queue can add any amount of latency. A new request that joins a queue 1,000 deep, drained at 100 a second, waits ten seconds. If that's longer than your timeout, every request in the queue is already dead, because its caller has gone, and you spend your capacity serving them anyway.
Shed by value, not by arrival order. Requests aren't all worth the same. A health check, a paying customer's checkout and a background backfill shouldn't be treated the same when you only have room for one of them. If you shed first the requests that are cheap to lose or easy to retry, the product keeps working while it's degraded.
Two published techniques do this well, and both are known by name.
Adaptive LIFO with CoDel, from Meta's paper "Fail at Scale". Under normal load, the queue is first in, first out (FIFO), which is fair. When a queue starts to form, it switches to last in, first out (LIFO), so the newest requests are served first. This sounds backwards, but it's right. The oldest request in a growing queue is the one whose caller has most likely given up already. CoDel, short for controlled delay, stops long queues forming in the first place. Once a queue has stayed non-empty for a while, CoDel gives each request a much shorter time limit for waiting in it. Meta's implementation is open source in its Wangle library, and Thrift, its remote procedure call (RPC) framework, uses it.
Client-side adaptive throttling, from Google's Site Reliability Engineering (SRE) book. Each client counts its own requests, and how many of them the backend accepted, over the last two minutes. It then rejects new requests itself, without sending them, with this probability:
max(0, (requests - K x accepts) / (requests + 1))
K is usually 2. So a client keeps sending everything until its requests reach K times its accepts, and only then starts dropping requests itself. The rejection happens in the client, before the network. That's why it works: an overloaded backend spends nothing rejecting traffic that was never sent.
Load shedding is not rate limiting
The two look alike, but they answer different questions.
Rate limiting is about fairness and abuse. It's decided per client, against a configured limit, and it applies whether or not you're busy. Load shedding is about staying up. It's decided by your own health, and it applies to everyone when you're in trouble. A client well under its rate limit still gets shed when the system is overloaded, and that's correct.
Build both. They're different code paths with different triggers. If you mix them up, you get a rate limiter that doesn't protect you and a load shedder that isn't fair.
Retries, which make all of this worse
Retries feel like they make a system more reliable. But they multiply the load at the exact moment load is the problem, and that makes them more dangerous than anything else here.
There are three rules, and the first matters most.
Retry at one layer, not every layer. Say each of four layers makes up to three attempts at the call below it. Then one request from the user can become 3^4 = 81 requests at the bottom. Each layer's policy looks sensible on its own.
Budget retries as a fraction of traffic. Instead of "3 attempts per call", the rule becomes "retries may be at most 10 percent of all requests". This is a retry budget. When things are healthy, almost nothing retries, so the budget is never reached. When everything is failing and every call wants a retry, the budget holds the extra load to 10 percent. With retries at one layer, that's 1.1x instead of 81x. Even if all four layers kept retrying, each would add at most 10 percent, and the total would be 1.1^4, about 1.5x. No other single change here cuts the retry load as much.
Back off exponentially, with jitter. Exponential backoff doubles the wait after each failed attempt: 100 ms, then 200 ms, then 400 ms. Jitter makes the wait random. Without jitter, every client that failed at the same moment retries at the same moment, again and again, in waves. Jitter spreads them out. Full jitter, a random wait between zero and the current backoff limit, is the standard advice. Under contention, when many clients compete for the same dependency, it does far better than backoff without jitter.
One more rule: never retry a request whose deadline has already passed. If you propagate deadlines, you know when that's true. If you don't, you'll retry work the caller has stopped waiting for.
The method
1. List every call that leaves the process. That includes the database, the cache and DNS: anything that can be slow.
2. Give each one a timeout from its latency distribution. Set it around the p99.9 of healthy latency. Propagate deadlines rather than repeating them.
3. Size a bulkhead from Little's Law. Take the concurrency at healthy latency and add headroom. If a dependency needs 50 slots when healthy, cap it near 75.
4. Ask what you return when it is unavailable. If there's a real answer, add a breaker. If there isn't, don't, and rely on the timeout and the bulkhead instead.
5. Bound the queues and decide the shedding order. Shed by value, not by arrival order, and write down what gets dropped first.
6. Fix the retries. Retry at one layer, with a budget as a percentage of traffic, and back off exponentially with jitter.
7. Decide the recovery behaviour. Limit the half-open probes, and decide what stops every client reconnecting in the same second when the dependency comes back.
Steps 2 and 6 fix more incidents than all the others together. Step 7 is the one teams skip, and that's why a recovery so often fails a second time.
Worked examples
There are four examples. Each one fails in a different way, and each ends in a decision.
A dependency nobody needed takes the service down
A product page calls a recommendation service to show "customers also bought". It's optional: the page works fine without it.
The recommendation service slows down to 5 seconds a response. It doesn't fail. It hangs. The product page has no timeout on that call, because the call never seemed important enough to configure.
At 500 requests a second, Little's Law gives L = 500 x 5 = 2,500 requests in progress, against a pool of 300. Within seconds every worker is stuck waiting for recommendations, and the product page stops serving anything at all. That includes pages that don't show recommendations.
So an optional dependency used up a resource that every request needs, and it never returned an error. Monitoring showed the recommendation service as degraded, not down. It showed the product page as down, with no errors of its own.
Decision: a 150 ms timeout, a semaphore bulkhead of 50 recommendation calls in flight, and a circuit breaker that returns an empty list when it's open. The breaker is safe here because "show the page without recommendations" is a real answer. Use all three, but the timeout does most of the work. With it, a stuck call holds a worker for at most 150 ms, so the recommendation calls need at most 500 x 0.15 = 75 workers out of 300, not 2,500. The bulkhead then caps them at 50.
A retry storm that outlives its cause
A database has a 30 second blip, a short outage. Every service makes up to three attempts per call, and there are four layers of calls between the user and the database.
The blip ends, and the database comes back. Straight away it gets up to 81 times its normal load, because every layer is still retrying, and users who gave up have sent their requests again. The database falls over again. Now there are more failures, so there are more retries.
This is a self-sustaining failure. The original cause is gone, but the system stays down, because the retries are now the load. Restarting services doesn't help, because the retry traffic is still waiting for them.
Decision: a retry budget that caps retries at 10 percent of requests. Retries happen at the edge only, not at every layer, with exponential backoff and full jitter. Load shedding at the database's front door lets it serve part of the traffic rather than none. Say this out loud: once a system is in this state, reducing load is the only way out, and the fastest way to reduce load is to reject it.
A recovery that fails because everyone comes back at once
A cache tier restarts and comes back empty. Every request now misses and goes to the database. The database was sized for a 99 percent hit rate, so it now sees 100 times its normal load.
This isn't a retry problem, and no dependency is slow. Here the recovery itself causes a spike in load, and every mechanism above is aimed at the failure, not at the return from it.
It gets worse if the breakers all opened during the outage with the same cooldown. They all reach the end of it at the same moment and send full traffic to a cold cache and a cold database together. A cold cache is an empty one, and a cold database has little of its working data in memory yet.
Decision: spread the recovery out over time. Limit half-open probes to a few calls at once. Add jitter to the cooldowns, so the breakers don't all close together. Put admission control at the database, a limit on how much new work it accepts, so that load climbs gradually instead of arriving all at once. The general point is that a recovering system has less capacity than the same system in its normal, steady state. If you treat the two as the same, you get a second outage.
A queue that turned a slowdown into an outage
An order service puts incoming requests into an unbounded queue in memory, and a pool of workers processes them. During a traffic spike, the queue grows.
Nothing returns an error. Memory use rises, latency rises, and clients start timing out at 2 seconds. Those clients retry, which adds more to the queue. The queue reaches 50,000 items, drained at 500 a second. That's 100 seconds of backlog.
Every item in that queue is now dead. Each one waits about 100 seconds in all, and its caller gave up after 2. The item at the front has a caller who left 98 seconds ago. The service runs at full capacity, producing responses that go nowhere. Even after the spike passes, it won't recover until the queue drains.
Decision: cap the queue at what can be drained within the client timeout. At 500 a second and a 2 second timeout, that's 1,000 items. Reject anything past that with a 503. Add adaptive LIFO, so that when a queue does form, the newest requests are served first, while their callers are probably still waiting. And drop any item whose deadline has already passed, instead of working on it.
Where it goes wrong
1. No timeout, which is the root of most of it
This is the most common cause of the failures in this article. Without a timeout, a slow dependency holds its slots for as long as it stays slow. No breaker or bulkhead can help, because nothing is ever recorded as a failure.
The default timeout in many HTTP clients is several minutes, or there is none at all. Check every client you use. It's about two hours of work, and it prevents more outages than anything else here.
2. A breaker on a dependency with no fallback
A hard dependency is one you can't answer without. If a breaker on it opens, a partial failure becomes a total one for as long as the cooldown lasts. The breaker also stops the retries that might have worked. If you can't answer "what do I return when this is open?", use a timeout and a bulkhead, not a breaker.
3. Retries at every layer
Each layer's retries look reasonable on their own, but together they multiply. Decide which layer owns retries, usually the one closest to the user, and make the others fail fast.
4. Backoff without jitter
Without jitter, retries line up and hit the dependency in waves, all at the same moments. Jitter spreads each wave into a steady trickle, and it costs one line of code.
5. Unbounded queues
Most frameworks give you an unbounded queue by default. It doesn't absorb load. It delays the failure and makes it worse, because by the time the work runs, it's worthless.
6. Bulkheads sized to the pool rather than to the need
A bulkhead set larger than the concurrency you'd ever reach does nothing. Size it from Little's Law at healthy latency. Accept that it will reject calls during a slowdown, because that's its job.
7. Everything recovers at once
The breakers share a cooldown, clients reconnect without jitter, and the caches start cold. The recovery is a spike in load, and it needs the same care as the failure. If your breakers all close in the same second, they behave like a retry storm with no jitter.
8. Shedding by arrival order
If you drop whatever arrives when you're full, a health check and a checkout are treated the same. Classify traffic by value in advance, so that what gets dropped is a product decision, not chance.
9. Testing none of it
Every mechanism here runs only during a failure. So unless you test it, it first runs in production, during an incident, in front of an on-call engineer who has never seen it work. Fault injection, causing failures on purpose in a test, is not optional for this kind of code. If a breaker has never opened in a test, you're guessing that it works.
If you memorise nothing else
| the line | why it holds |
|---|---|
| Slow is more dangerous than down | slow holds concurrency slots; down releases them |
L = λ x W explains all of it | concurrency is arrival rate times time in system |
| Timeouts first, always | without one, breakers never trip and bulkheads just fill |
| Set timeouts from p99.9, not round numbers | a round number either fires constantly or never |
| Propagate deadlines, do not repeat them | three 300 ms timeouts in series is a 900 ms budget |
| Breakers need a fallback | no answer when open means you built an outage switch |
| Half-open must be rate-limited | full traffic at a recovering dependency knocks it back over |
| Size bulkheads from healthy concurrency | λ x W plus headroom, not the size of your pool |
| Reject rather than queue | a fast 503 beats a slow success nobody is waiting for |
| Bound every queue | queue depth divided by throughput is added latency |
| Retry at one layer only | 3 attempts x 4 layers is 81x amplification |
| Budget retries as a percentage of traffic | caps the storm at 1.1x instead of 81x |
| Always jitter the backoff | otherwise failures synchronise into waves |
| Shed by value, not arrival | so degradation is a product decision |
| Recovery capacity is not steady-state capacity | cold caches and synchronised reconnects are their own spike |
| Load shedding is not rate limiting | one is survival, the other is fairness |
What is expected at each level
Mid-level
Knows what a circuit breaker is and can describe the three states. Adds timeouts when prompted, usually as a round number rather than from a latency distribution. Treats retries as always good and does not raise how they multiply load. Tends to propose a queue as the answer to overload, without bounding it or asking what happens when it is full.
Senior
Reaches for timeouts first and sets them from observed latency. Bounds queues and prefers rejecting to queueing, and can say why. Puts breakers only where a fallback exists and can say what is served when one is open. Knows retries multiply load and applies backoff with jitter. Sizes bulkheads from the expected concurrency rather than picking a number.
Staff+
Derives the whole design from Little's Law and can show that a slow dependency shrinks capacity by the same factor as the slowdown. Uses a retry budget as a fraction of traffic rather than a per-call count, and explains that it keeps the extra load small however many layers there are. Treats recovery as a separate load event with its own controls: jittered cooldowns, limited half-open probes, and admission that ramps up against a cold cache. Tells load shedding apart from rate limiting and builds both. Insists the failure paths are tested with fault injection, because code that only runs during an incident is untested code.
Sources
Every real-world figure and named technique here comes from a published source. The arithmetic is derived from Little's Law and can be checked directly.
- Michael Nygard, Release It!, which named and popularised both the circuit breaker and the bulkhead as software patterns.
- Google's Site Reliability Engineering book, chapter on handling overload, for client-side adaptive throttling over the last two minutes of each client's history, and the rejection probability
max(0, (requests - K x accepts) / (requests + 1))with K typically 2. The important property is that the rejection happens in the client, before the request reaches the network. - Ben Maurer, Fail at Scale, ACM Queue 2015, for adaptive LIFO combined with CoDel at Meta. The queue is FIFO under normal conditions and switches to LIFO once a queue forms, because the oldest request in a growing queue is the one most likely to have been abandoned. It is implemented in Meta's open-source Wangle library and used by Thrift.
- The AWS Builders' Library article on timeouts, retries and backoff with jitter, for the result that, under contention, full jitter does much better than exponential backoff without jitter, and better than equal jitter.
- Little's Law,
L = λW, which holds for any stable system, whatever the distributions of arrival and service times. That is why the same arithmetic covers thread pools, connection pools and queues alike.