SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
  • Service Discovery
  • API Gateway Pattern
  • Backend for Frontend (BFF)
  • Sidecar Pattern
  • Circuit Breaker
  • Bulkhead
  • Strangler Fig
  • Service Mesh
  • Database per Service
  • Timeouts and Deadlines
  • API Composition
  • Anti-Corruption Layer
  • Ambassador Pattern
  • Idempotent Consumer and Inbox Pattern
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Architecture/Microservices Patterns

Bulkhead

Split resources into separate compartments so one overload cannot sink the whole ship.

⏱ 12 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

The bulkhead pattern splits your resources (threads, connections, memory, even whole servers) into separate compartments, so a problem in one part cannot use up everything.

  • The name comes from ships: walls inside the hull keep a leak in one room from sinking the whole ship.
  • Give each dependency or each kind of work its own limited pool. When one is slow or broken, only its pool fills up.
  • The rest of the system keeps working, maybe without the one broken feature.

02Concept: What is it?

Imagine a service that calls three others: checkout, reports and search. It handles all calls with one shared pool of 20 threads. One day the reports service becomes very slow. Every report call now holds a thread for 8 seconds. Soon all 20 threads are stuck on reports. Checkout and search are healthy, but they cannot get a thread, so they fail too. One slow neighbour took everyone down.

The bulkhead pattern avoids this by partitioning the resource. For example: 12 threads for checkout, 4 for search and 4 for reports. When reports is slow, its 4 threads fill up, and extra report requests are rejected quickly. Checkout and search still have their own threads, and keep running.

Shared pool vs compartments
One shared pool
πŸ›’Checkout
πŸ”ŽSearch
πŸ“ŠReportsslow
↓all take from one pool
🧡20 threadsall stuck on reports
Bulkheads
🧡Checkout12 threads
🧡Search4 threads
🧡Reports4 threads, full
Only the reports compartment is flooded
With walls, a leak stays in one room.
🧠Limit the damage, not the failure
A bulkhead does not stop the failure. It makes sure the failure has a small, known blast radius.

03Real-Life Example

🍡The Ship with Watertight Rooms
A ship has many rooms separated by strong walls called bulkheads. If a rock cuts a hole in one room, water fills that room only. The doors between rooms are closed, the rest of the ship stays dry, and the ship keeps floating. Without the walls, one hole would fill the entire ship and it would sink. A food court works the same: if the pizza stand has a huge queue, the sushi stand still serves people, because each stand has its own line.
Ship
Bulkhead pattern
The ship
The whole system
A watertight room
A resource pool for one dependency or feature
The wall between rooms
The limit that keeps pools separate
A hole and flooding
A slow or failing dependency
Water stays in one room
Only that pool fills up
The ship keeps floating
Other features keep working
A room that is too small
A pool that is too small for its normal traffic
A request meets a full compartment
πŸ“¨Requestfor reports
→↓
🧱Reports pool4 of 4 busy
→↓rejected fast
🎭Fallbackor a clear error

04Why Do We Need It?

πŸ”’Contain failures
A slow dependency can only use its own share of the resources.
πŸ›’Protect what matters
Reserve capacity for the most important work, like checkout, so it always has room.
🧯Stop cascading failure
A sick service no longer drags its callers down with it.
🀝Fair sharing
One noisy customer or feature cannot take everything from the others.
πŸ“Predictable limits
You know the most each part can ever use.
πŸ§ͺEasier to reason about
When something fails, you know which compartment to look at.
Do not let one bad neighbour use all the shared resources. Give each part its own limited share.

05Where Do We Use It?

🧡Thread pools
A separate thread pool for each downstream service or each kind of task.
πŸ”—Connection pools
A separate database or HTTP connection pool per dependency.
🚦Concurrency limits
A semaphore that allows at most N calls at once to one dependency.
πŸ“¦Containers and pods
CPU and memory limits per container, so one cannot starve others on the node.
🏒Tenants and customers
Separate capacity (or a separate deployment) for large or risky customers.
πŸ—οΈCells and shards
Split the whole system into independent cells, so an outage hits a small share of users.

06Types / Parts / How It Works

Levels of isolation

StyleHow it isolatesGood and bad
Thread-pool bulkheadA dedicated thread pool per dependencyStrong isolation and a clear timeout. Costs extra threads and context switching.
Semaphore bulkheadA counter limits concurrent calls, calls run on the caller's threadLight and cheap. A hung call still holds the caller's thread, so timeouts matter.
Connection-pool bulkheadSeparate connection pools per database or APIStops one slow query path from using every connection.
Process or containerSeparate process, container or VM with CPU and memory limitsStrong isolation, even for memory leaks or crashes. Higher cost.
Service or cellSeparate deployments for different traffic or customersThe best isolation, with the most operations work.

What to separate by

Ways to draw the walls
By dependency
πŸ’³Payments pool
πŸ“§Email pool
By importance
⭐Critical pool
🐒Best-effort pool
By customer
🏒Big client
πŸ‘₯Everyone else
Per dependency Per priority Per tenant
Pick the split that matches how your failures actually happen.
VisualizerOne shared pool vs separate compartmentsStart with the shared pool and watch the slow reports service eat every thread. Then switch to bulkheads. Try a smaller checkout compartment to see that sizing matters.
How are threads arranged?

Checkout: 20 requests/s, 100 ms each (needs about 2 threads). Reports: 6 requests/s, 300 ms at first. Slider "Reports compartment" only matters in bulkhead mode.

Threads at second 30: cyan = checkout, purple = reports, dark = free
Rejected checkout requests per second (red)
Threads held by reports (purple)
0 sslowdown starts at 5 s30 s
Checkout served
27%
of finished requests
Checkout rejected
439
no free thread
Reports served
135
requests
Reports rejected
24
no free thread
The slow reports calls are holding the threads. Checkout is not slow, but it found no free thread 439 times and was rejected. One sick service took everything down.

A simplified model with a simulated clock (no random numbers). A request with no free thread in its pool is rejected at once (no waiting line). Real bulkheads may add a small queue.

07How to Use It / Steps / Implementation

Adding bulkheads

  1. 1
    List your dependencies
    Write down every database, service and queue you call, and how important each one is.
  2. 2
    Find the shared resources
    Look for pools that everything shares: one thread pool, one connection pool, one queue.
  3. 3
    Decide the walls
    Split by dependency, by priority or by tenant. Keep the number of compartments small.
  4. 4
    Size each compartment
    Use the idea: concurrent calls β‰ˆ requests per second Γ— time per call. Add some room for bursts. Then measure.
  5. 5
    Reject, do not queue forever
    When a compartment is full, fail quickly or allow a short queue. A long queue only moves the waiting around.
  6. 6
    Add timeouts and fallbacks
    A bulkhead limits how many calls wait. A timeout limits how long. A fallback decides what the user sees.
  7. 7
    Watch each compartment
    Track usage, rejections and wait time per compartment, and adjust sizes with real traffic.
πŸ’‘Pair it with a circuit breaker
The bulkhead keeps a sick dependency from using all your resources. The circuit breaker stops calling it at all. Together they give strong protection.
⚠️Too many walls waste capacity
Free threads in one compartment cannot help a busy one. Do not split into dozens of tiny pools. Start with a few well-chosen ones.

08Key Terms to Know

TermMeaning in easy words
BulkheadA wall that keeps one part of a system from affecting another
CompartmentOne isolated share of resources (a pool, a limit, a server)
Blast radiusHow much of the system is hurt when something fails
Noisy neighbourOne user or feature that takes more than its share and hurts others
Thread poolA fixed group of worker threads that run tasks
SemaphoreA counter that allows only N things to happen at once
Cascading failureA failure that spreads from one part to the next
Resource exhaustionRunning out of threads, memory or connections
Load sheddingRejecting some work on purpose to protect the rest
Cell-based architectureSplitting the whole system into independent copies, each serving part of the users
Concurrency limitThe most calls allowed at the same moment

09Pros, Cons and Trade-offs

βœ… Pros
  • Failures stay in one compartment
  • Protects critical features
  • Stops one dependency using every thread
  • Fair sharing between tenants and features
  • Makes problems easier to locate
  • Works with breakers and timeouts
⚠️ Cons
  • Idle capacity in one compartment cannot help another
  • Sizes need tuning and re-tuning
  • More pools and settings to manage
  • Thread pools add overhead
  • Rejections can be seen by users
  • Does not fix the failing dependency itself

Trade-offs

ChoiceWe gainWe lose
More compartmentsFiner isolationMore wasted idle capacity and more settings
Fewer compartmentsBetter use of resourcesWeaker isolation, a bigger blast radius
Small compartmentA strong cap on damageRejections even in normal bursts
Large compartmentHandles bursts wellA slow dependency can still hold many resources
Thread-pool bulkheadStrong isolation and clean timeoutsMore threads, more context switching
Semaphore bulkheadVery lightRuns on the caller's thread, so a stuck call still holds it

10Common Problems and Mistakes

Common mistakes

  1. One shared pool for everything. The exact problem the pattern is meant to avoid.
  2. Guessing the sizes. Too small gives rejections in normal traffic. Too big gives no protection.
  3. No timeouts. Calls stay in a compartment forever, so even a small pool fills and stays full.
  4. Unbounded queues. A huge waiting line hides the problem and makes every user wait.
  5. Splitting too much. Dozens of tiny pools waste capacity and are hard to manage.
  6. Forgetting hidden shared parts. Separate thread pools, but one shared database connection pool or one shared CPU is still a shared fate.
  7. Never checking rejection metrics. A bulkhead hiding constant rejections is a quiet outage for one feature.

Things to watch

🚫Rejection rate
A steady rise means the compartment is too small or the dependency is unhealthy.
πŸ“ˆUtilisation
A pool always near 100% needs a look. One always near 0% is wasted.
πŸ”—Shared resources
Check for a common database, cache or network link that still joins the compartments.
βš–οΈPriority balance
Important traffic should have room even in a bad day. Review the split every few months.

11Real-World Examples

β˜•Resilience4j
Offers semaphore and thread-pool bulkheads for Java, often used with a circuit breaker.
πŸ”·Polly in .NET
Includes a bulkhead isolation policy that limits parallel calls and queue size.
☸️Kubernetes limits
CPU and memory requests and limits, and namespaces with quotas, act as resource bulkheads.
πŸ•ΈοΈEnvoy limits
Envoy can cap connections, pending requests and active requests to each upstream cluster.
☁️Cell-based design
Large cloud systems split users into cells, so one failed cell affects only a small share (Amazon has described this).
πŸ’³Priority lanes
A payment system keeps separate capacity for checkout and for batch jobs like refunds reports.
πŸ“Note
Library features and names change between versions. Check the current docs before choosing settings.
Mini case: separate pools per dependency
🧠Order service
→↓16 threads
πŸ’³Payments
🧠Order service
→↓4 threads (full)
πŸ“§Email providerslow
A slow email provider cannot block payments.

12Related Topics to Read Next

Circuit Breaker→

Stops calls to a failing dependency, a good partner for bulkheads.

Rate Limiting→

Caps how much traffic a client or feature can send.

Connection Pooling→

A pool is a limited resource, and bulkheads split pools.

Microservices→

Many dependencies mean many chances for one to go slow.

Single Point of Failure (SPOF)β†’

A shared pool can be a hidden single point of failure.

Availability→

Containing failures keeps more of the system available.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”What: split resources into isolated compartments, like walls in a ship.
  • βœ”Why: one slow or failing part must not use up everything.
  • βœ”How: separate thread pools, connection pools, limits or deployments.
  • βœ”Split by: dependency, priority or tenant. Keep it to a few compartments.
  • βœ”Size: requests per second Γ— call time, plus headroom. Then measure.
  • βœ”Full pool: reject fast or a short queue, plus a fallback. Always set timeouts.
  • βœ”Pairs with: circuit breaker, timeouts, rate limiting.
  • βœ”One line: β€œGive each part its own share, so one leak cannot sink the ship.”
← Previous
Circuit Breaker
Next β†’
Strangler Fig