Bookmarks

Bulkhead

A resilience pattern: the system’s shared resources are divided into isolated pools so that a failure in one compartment does not knock out the rest.

Also: bulkhead pattern, cell-based architecture

checked 8 Nov

All terms

The name comes from shipbuilding: bulkheads divide the hull into watertight compartments, so a breach in one does not sink the whole ship. In software systems, separate pools of threads, connections and memory play the role of bulkheads: a hung dependency exhausts its own limit and stalls on its own, while the rest of the system keeps working.

What is divided and how

ResourceHow it is dividedExample
Execution threadsa separate pool per external dependencythe payment gateway call gets its own 20 threads, search — its own 40
Database connectionspools per service or tenantthe reporting module gets 5 connections out of 100, not the whole database
Process and memoryseparate containers with CPU and memory limitsthe recommendation generator does not share memory with the payment service
Service instancesgroups of nodes by importance of consumersthe critical order flow is served by dedicated nodes, not ones shared with analytics

Example

A service handles requests with 200 worker threads and calls two external APIs. Without isolation, a hung partner API can take up all 200 threads — and both user sign-in and the shopping cart go down with it. With bulkheads, 50 slots are set aside for partner API calls: the worst case is that the partner API is unavailable, while sign-in and the shopping cart keep working on the remaining 150.

javaA compartment for 50 concurrent calls in resilience4j
Bulkhead bulkhead = Bulkhead.of("partner-api",    BulkheadConfig.custom()        .maxConcurrentCalls(50)              // compartment capacity (25 by default)        .maxWaitDuration(Duration.ofMillis(100)) // wait for a slot for at most 100 ms, then reject        .build());

In resilience4j, a compartment is a semaphore on the number of concurrent calls; there is also a variant built on a separate thread pool with a queue. When a compartment is full, a new call waits for a free slot for at most the specified time and is then rejected — instead of hanging in the common pile of threads.

When to use it

  • resources need to be isolated for specific dependencies, so that a failure in one does not touch the whole application
  • critical consumers need to be separated from ordinary ones and given their own service level
  • a cascading failure needs to be stopped before it spreads through shared resources

Granularity is chosen based on load and availability requirements: for example, one compartment per tenant, or several tenants per compartment; each compartment is monitored separately, including its SLA. Bulkheads rarely work alone — they are combined with retries, circuit breakers and rate limiting. The cost of the approach is that resources sit idle in empty compartments and configuration becomes more complex; if the project is not prepared for such overhead, the pattern is not used.

Origin of the term

The pattern joined the stability patterns from Michael Nygard’s book “Release It!” (Pragmatic Bookshelf, 2007; second edition 2018). At production scale, bulkheads were cemented by libraries such as Hystrix and resilience4j, along with platform limits — request quotas and container resource limits in Kubernetes.

Sources

the term is written from these pages

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • circuit breaker

    A circuit breaker stops calling a failing dependency altogether for a while, while bulkheads limit how many of its calls can take up shared resources.

  • rate limiting

    Rate limiting counts requests per second and protects the provider from overload, while bulkheads divide the system’s own resources between consumers.

In depth in the references

where the topic is covered in detail