Bulkhead Pattern

Isolating resources (thread pools, connection pools, instances, cells) so that one failing dependency or tenant cannot exhaust capacity for everything else.

Intent

Named after watertight compartments in ships, bulkheads partition resources so a failure floods only one compartment. Without them, a slow dependency consumes all request threads or connections and the whole service stops responding, even for requests that never touch that dependency.

flowchart LR
  REQ[Incoming requests] --> APP[Service]
  APP --> P1[Pool A: 20 permits] --> PAY[Payment API]
  APP --> P2[Pool B: 10 permits] --> RECO[Recommendations API<br/>slow]
  APP --> P3[Pool C: 30 permits] --> INV[Inventory API]
  RECO -. saturates only Pool B .-> P2

Levels of bulkheads

Level Example
Code Separate semaphores or thread pools per dependency
Connection Separate HTTP/DB connection pools
Process Separate deployments for critical vs non-critical endpoints
Infrastructure Separate node pools, clusters, queues per workload or tenant tier
Cell Independent stacks per customer segment

Java example (Resilience4j semaphore bulkhead)

BulkheadConfig cfg = BulkheadConfig.custom()
    .maxConcurrentCalls(10)
    .maxWaitDuration(Duration.ofMillis(20))   // fail fast instead of queueing
    .build();
Bulkhead recoBulkhead = Bulkhead.of("recommendations", cfg);

Supplier<List<Product>> call = Bulkhead.decorateSupplier(recoBulkhead, () -> reco.top(userId));
List<Product> items = Try.ofSupplier(call).recover(BulkheadFullException.class, e -> List.of()).get();

With virtual threads, threads are cheap, so semaphore bulkheads (concurrency limits) matter more than thread-pool bulkheads: the scarce resources are connections and downstream capacity.

Pros and cons

Pros Cons
Contains failures to one area Capacity fragmentation and tuning effort
Protects critical paths Too-small pools reject legitimate load
Works well with circuit breakers More configuration to maintain

Interview questions

Give a real example where a bulkhead would have prevented an outage.

A product page service shares one HTTP connection pool across all dependencies. The reviews service slows down; all connections are held waiting; checkout calls through the same service time out. Separate pools per dependency (and a circuit breaker on reviews) would have kept checkout working.