What it is
A bulkhead partitions a shared resource so that one consumer can use only a bounded part of it. The name comes from ships, whose hulls are divided into watertight compartments: a breach floods one compartment, not the whole ship. In software the resource is usually a pool of threads, connections or concurrent calls, but the same idea applies to instances, clusters and whole regions.
Why it exists
Resources a service holds while it waits, threads, async slots, database or HTTP connections, are typically shared by everything the service does. When one dependency slows down, calls to it hold those resources longer (Little’s law: in use = arrival rate × time held). At 40 calls a second, a dependency that goes from 40 ms to 800 ms needs 32 workers instead of 1.6. In a shared pool those workers are taken from everyone, so features that never touch the slow dependency queue, time out and fail. Often the slow dependency is the least important one (recommendations, analytics, avatars) and the starved feature is the most important one (checkout, login).
How it works
Partition the resource. Give each downstream dependency (or group of calls) its own pool or concurrency limit: for example 6 workers for recommendation calls and 6 for payment calls instead of 12 shared. A call that cannot get a slot in its compartment is rejected or waits briefly in a short, bounded queue.
Two common implementations. Pool isolation runs each dependency’s calls on its own thread or connection pool. Semaphore isolation keeps a counter of in-flight calls per dependency on the caller’s own threads, cheaper, but it only limits concurrency and cannot abandon a call stuck in a blocking read, so it relies on timeouts. With async I/O, a per-dependency concurrency limit plays the same role.
Fail fast and fall back. When a compartment is full, return quickly: an error the caller can handle, a cached or default value, or the page without the optional part. A long queue in front of a full compartment only makes every request slow before failing it.
Size from load. Busy slots ≈ requests per second × seconds each holds a slot. Add headroom for bursts (often 1.5–2×), and cap it so a slowdown cannot grow beyond its share.
When to use it
- A service calls several dependencies of different importance or reliability.
- One noisy client, tenant or batch job could starve interactive traffic.
- Critical paths (checkout, authentication) share infrastructure with non-critical ones.
- Large fleets, where independent cells limit how many customers one bad deploy or failure can reach.
When not to
- A service with a single dependency: there is nothing to isolate from, a timeout and a breaker are enough.
- Very small pools where splitting leaves each compartment too small to absorb normal bursts.
- As a substitute for timeouts: without them, a compartment fills with stuck calls and stays full.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Shared pool | Best utilisation; idle capacity serves anyone | One slow dependency can take everything |
| Pool per dependency | Failures stay in their compartment | Idle capacity cannot be lent; more pools to size and monitor |
| Thread-pool isolation | Can abandon blocked calls, strong isolation | Thread hand-off overhead, more threads |
| Semaphore / concurrency limit | Cheap, works with async I/O | Needs timeouts to free stuck calls |
| Short queue on a compartment | Fast rejection and fallback | Some requests rejected during normal bursts |
| Separate instances or cells | Isolation from crashes, deploys and noisy neighbours too | More infrastructure, routing and capacity planning |
Alternatives
- Timeouts bound how long one call can hold a slot; they shrink the problem but do not cap the share.
- Circuit breakers stop calling a failing dependency; combine them with bulkheads.
- Adaptive concurrency limits adjust the limit from observed latency instead of fixed sizes.
- Rate limits and quotas per tenant protect a shared service from individual callers.
- Asynchronous processing moves non-critical calls off the request path entirely.
Failure modes
- Compartment too small: normal peaks are rejected, as in the surge step, while neighbours sit idle.
- Compartment too large: a slow dependency still takes almost everything; the isolation is cosmetic.
- Hidden shared resources: separate thread pools that still share one database connection pool, one HTTP client connection limit or one event loop.
- No timeouts inside the compartment: it fills with stuck calls and never drains.
- Long queues in front of compartments: requests wait, then fail, and users see slowness instead of a quick fallback.
- No fallback: isolation works, but the page still errors because the optional part is treated as required.
In production
Use the bulkhead or concurrency-limit features of your resilience library or mesh (Resilience4j and Polly bulkheads, Envoy circuit-breaking thresholds such as maximum connections and pending requests per cluster), and separate HTTP and database connection pools per dependency. Size each from measured rate × latency with headroom, and alert on rejections per compartment. Keep critical and best-effort traffic on separate instances where it matters, and consider cell-based architectures for large multi-tenant systems. Always pair bulkheads with timeouts, a breaker and a defined fallback, and test them by injecting latency into one dependency and checking that the others stay healthy.
Common misconceptions
- "A bulkhead makes the slow dependency work." It only limits the damage; that feature still degrades.
- "Separate services means separate resources." A shared pool, client or proxy in between can still couple them.
- "Bulkheads are free." They cost pooled efficiency: compartments cannot borrow from each other.
- "Timeouts make bulkheads unnecessary." A timeout bounds the time per call; at high traffic even bounded calls can fill a shared pool.
Interview angle
When a design has one service calling several dependencies, point out that a slow optional dependency can exhaust shared threads or connections and take the critical path down. Propose per-dependency pools or concurrency limits, sized with Little’s law, with a short queue, a fallback and a circuit breaker. Extending the idea to tenant isolation and cells shows you can apply it at the architecture level, and naming the cost (no borrowing between compartments) shows judgement.
Model assumptions
The simulation is a simplified model, not a benchmark. Product pages send 40 requests per second and checkout 20 (Poisson); both clients time out after 1.5 s. The API has 12 workers (10 ms of own work each, lognormal, cv 0.3), and a worker is held for the whole call to the dependency. Recommendations and Payments each have 8 workers with 40 ms and 60 ms mean service times; "slow" makes Recommendations 20× slower. In the shared case the engine routes the two features through a balancer’s read/write split: checkout requests are flagged as writes and go to Payments, product-page requests go to Recommendations; nothing is written. After the split, the recommendations pool has 6 workers and room for 4 waiting calls, the checkout pool 6 workers and room for 20. Fallbacks are not modelled: a rejected product page is counted as a failure, and the fallback step describes what the page would show. Latency percentiles (P50, P95, P99) are computed over the requests that succeeded in the last 5 simulated seconds: failed, rejected and timed-out requests are not in them and are counted in the Errors tile, which is always shown next to them. Rejecting or timing out the slowest requests therefore improves the percentiles while making the system less reliable, so read the two together. Numbers show behaviour and orders of magnitude only.