Course contents

09. Reliability and Resilience Lesson 5 of 10

Bulkhead

Watch a slow, non-essential dependency drain a shared worker pool and take checkout down, then split the pool so only one feature degrades.

12 minIntermediate6 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • A worker waiting on a dependency is busy; a slow dependency can hold every worker in a shared pool.
  • Then features that never call that dependency fail too.
  • A bulkhead gives each dependency (or tenant, or criticality class) its own bounded share.
  • A full compartment should reject fast and fall back, not queue.
  • Compartments cannot lend idle capacity: size each from its own load plus headroom.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

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.

The lesson as textEvery step of the simulation, written out.
  1. 1. Two features, one pool of workers

    One API serves two features. Product pages (40 requests a second) call the Recommendations service; Checkout (20 a second) calls Payments. Both use the same 12 workers.

    A worker is held for the whole request, including the call to the dependency, so a product page holds one for about 55 ms and a checkout for about 75 ms. Together that keeps only about 4 of the 12 workers busy. Everything is fast and nothing fails.

    The pool is shared because that is the default: one thread pool, one connection pool, one process.

    Scene: Product pages and checkout both go through one API with 12 shared workers; product pages call Recommendations, checkout calls Payments. Few workers are busy and nothing fails.

    Key idea: A shared pool is efficient while every dependency is healthy: idle workers serve whoever needs them.

  2. 2. A non-essential dependency takes checkout down

    One second in, Recommendations becomes 20× slower: each call now takes most of a second. Product pages keep arriving at 40 a second and each one now holds an API worker for that long.

    Within a moment all 12 workers are waiting on Recommendations. Checkout requests queue behind them, wait past the 1.5 s timeout or are rejected when the queue is full. Checkout fails although Payments is healthy and almost idle.

    Recommendations is a nice-to-have. Checkout is the business. One slow, unimportant dependency has drained a resource both features needed.

    Scene: Recommendations slows down. Product-page requests hold every shared API worker, checkout requests queue behind them and time out or are rejected, while Payments sits almost idle.

    Key idea: In a shared pool, the slowest dependency decides how many workers everyone else gets: eventually none.

  3. 3. Separate pools: only one feature degrades

    Ships are divided into watertight compartments, bulkheads, so a leak floods one compartment and not the whole hull. Here the API’s 12 workers are split into two pools of 6: one only for calls that need Recommendations, one only for checkout.

    Recommendations is still 20× slower. Its pool fills up and, with only a short queue, rejects extra product-page requests at once; those pages render without recommendations or show an error. But the checkout pool is untouched: no errors, normal latency, Payments busy as usual.

    Same total capacity, same slow dependency. The difference is where the damage stops.

    Scene: The API workers are split into a recommendations pool and a checkout pool of 6 each. With Recommendations still slow, its pool is full and rejects product-page requests, while checkout succeeds with normal latency.

    Key idea: A bulkhead caps how much of a shared resource one dependency can take, so its failure stays in its own compartment.

  4. 4. What the full compartment returns

    The recommendations pool is full, so the question is what a product page shows. Failing the whole page would turn a missing widget into a missing shop. The usual answer is a fallback: render the page without recommendations, or with a cached "popular items" list.

    The short queue on that pool matters. With room for only 4 waiting calls, extra requests are rejected in microseconds instead of waiting a second for a worker, so the page can fall back quickly. A long queue would only make every product page slow before failing it.

    This is also where a circuit breaker fits: once Recommendations is clearly failing, stop calling it at all and go straight to the fallback.

    Scene: Recommendations is still slow. Its pool rejects extra requests immediately, so product pages can quickly fall back to rendering without recommendations; checkout is unaffected.

    Key idea: A bulkhead decides where failure stops; a fallback decides what users see; a short queue makes the failure fast.

  5. 5. The price: a compartment cannot borrow

    Recommendations is healthy again. Then checkout traffic surges to 90 requests a second (a sale starts). At about 75 ms per checkout that needs nearly 7 busy workers, more than the checkout pool’s 6.

    The checkout pool saturates and checkout requests start failing, while the recommendations pool next door has idle workers it is not allowed to lend. A shared pool of 12 would have absorbed this surge.

    That is the trade-off of every bulkhead: isolation costs flexibility. Size each pool from its own traffic with Little’s law (busy workers = requests per second × seconds held), add headroom, and revisit the sizes when traffic changes.

    Scene: Checkout traffic surges to 90 requests per second. The checkout pool of 6 saturates and checkout requests fail, while the recommendations pool has idle workers it cannot lend.

    Key idea: Bulkheads trade pooled efficiency for isolation. Size each compartment from its own load (rate × time held) plus headroom.

  6. 6. Compartments everywhere

    Traffic is back to normal: 40 product pages and 20 checkouts a second, each feature in its own pool, everything healthy.

    The same idea works at every level: a thread or connection pool per dependency inside a service (what you just saw), a concurrency limit per downstream call, separate instances or clusters for critical and non-critical traffic, per-tenant quotas so one noisy customer cannot starve the others, and whole cells of infrastructure that fail independently.

    Pair it with timeouts (so a compartment drains), fallbacks (so users get something) and circuit breakers (so a failing dependency is not called at all).

    Scene: Normal traffic with separate recommendations and checkout pools; both features are fast and nothing fails.

    Key idea: Partition shared resources by dependency, criticality or tenant, so one failure cannot consume everything.