Course map

Topic 153 / Core

Bulkhead

Chapter 9.4 · Resilience Patterns

What and why

Even with timeouts and backoff (→ 152), one slow dependency can still consume every thread or connection a service has, if all callers to all dependencies share the same pool (→ 77, → 103 — "thread and connection pool exhaustion"). A bulkhead isolates resources per dependency — separate thread pools, separate connection pools, separate queues — so that one dependency's slowness drains only its own pool, leaving capacity for calls to every other dependency. Builds on: → 152 (retry storms and cascading failure are exactly what bulkheads contain).

Diagram

Without bulkheads                      With bulkheads
──────────────────                      ──────────────
   [shared pool: 100 threads]            [Pool A: 30] → Dependency A (slow)
        │        │        │              [Pool B: 30] → Dependency B (fine)
        ▼        ▼        ▼              [Pool C: 30] → Dependency C (fine)
     Dep A    Dep B    Dep C
   (slow — ties up the whole pool,     Dep A exhausts only its own 30 —
    starving calls to B and C too)      B and C keep serving normally

How it works

  1. Identify dependencies whose failure modes are independent — a slow payment gateway should never starve calls to a fast internal cache.
  2. Allocate a separate resource pool per dependency (or per class of dependency): a fixed-size thread pool, connection pool (→ 77), or request queue.
  3. Size each pool to the dependency's normal concurrency need plus a margin — not so large that exhaustion still cascades, not so small that normal load gets rejected.
  4. When a pool fills (its dependency is slow), reject or queue new calls to that dependency specifically — callers to every other dependency are unaffected.
  5. Combine with a circuit breaker (→ 151) per dependency: the bulkhead bounds the damage while the breaker is also open, and the breaker's fast failures reduce how quickly the pool fills in the first place.

Practical example

(illustrative). A service with one shared pool of 100 connections calls three dependencies; Payment starts timing out and, within seconds, all 100 connections are waiting on Payment, so the otherwise-healthy calls to Catalog and Inventory start failing too — purely from pool exhaustion, not from their own problems. Splitting into three pools of roughly 30 each means Payment can still exhaust its own 30, but Catalog and Inventory keep serving normally the whole time.

When to use it

  • Use when: a service calls multiple independent dependencies and a failure in one must not be allowed to starve calls to the others.
  • Avoid when: there is only one dependency, or all dependencies genuinely share fate (if one is down the others are useless anyway) — separate pools add overhead without buying isolation.
  • Failure scenarios: pools sized too small reject normal traffic even when the dependency is healthy; pools sized too large just delay the exhaustion rather than preventing it; forgetting to bulkhead a dependency added later ("just reuse the shared pool for now") quietly reopens the exact failure the pattern exists to prevent.
  • Simpler alternative: if a service only ever calls one dependency, or the dependencies are few and reliably fast, a single shared pool sized with headroom is simpler and the isolation buys nothing yet.

Practice

(Pattern kind — implement minimal, spot the misuse; 20 min, two small processes). Build a service with two downstream dependencies on a single shared pool of 10 workers; make one dependency hang (never respond) and confirm calls to the other dependency eventually stall too. Then split into two pools of 5 each and confirm the healthy dependency keeps responding while the hanging one exhausts only its own pool.

Done when you've reproduced the shared-pool starvation and shown it gone after isolating the pools.

Key takeaway

A bulkhead isolates resource pools per dependency so one dependency's failure drains only its own capacity. Done when you can: size and wire a separate pool per dependency and demonstrate isolated failure under load. Used next in → 154 (graceful degradation — what each isolated failure degrades to).

References

A pattern language for microservices — see references.md.

Source directory

Search the guide