← Back to Gallery
🚢
Bulkhead Pattern
Definition
The Bulkhead Pattern isolates elements of an application into pools so that if one fails, the others continue to function. Named after ship compartments that prevent water from spreading across the vessel, this pattern partitions resources to prevent cascading failures and improve system resilience.
When to Use It
- Isolating critical resources from less critical ones
- Preventing resource exhaustion across services
- You need to guarantee resources for critical operations
- Protecting against cascading failures
- Multi-tenant applications requiring isolation
- Systems with varying SLA requirements
Pros & Cons
✓ Pros
- Isolates failures to specific partitions
- Prevents complete system failure
- Guarantees resources for critical functions
- Better performance predictability
- Improved overall system resilience
- Easier to identify bottlenecks
✗ Cons
- Increased resource overhead
- Potential resource underutilization
- More complex configuration
- Requires careful capacity planning
- May waste resources during low load
- Additional monitoring needed
Architecture Diagram
Connection Pool Bulkhead Example
=================================
Without Bulkhead (Single Pool - Risk of Exhaustion):
─────────────────────────────────────────────────────
┌─────────────────────────────────────┐
│ Single Connection Pool │
│ (50 connections total) │
│ │
│ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ │
│ All consumed by slow operations! │
└────────────┬────────────────────────┘
│
┌────────┼────────┐
│ │ │
▼ ▼ ▼
┌────┐ ┌────┐ ┌────┐
│API │ │API │ │API │
│ A │ │ B │ │ C │
│ ✗ │ │ ✗ │ │ ✗ │
└────┘ └────┘ └────┘
Blocked Blocked Blocked
With Bulkhead (Isolated Pools - Failure Contained):
────────────────────────────────────────────────────
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Pool A │ │ Pool B │ │ Pool C │
│ (20 conn) │ │ (15 conn) │ │ (15 conn) │
│ │ │ │ │ │
│ ▓▓▓▓▓▓▓▓▓▓▓▓ │ │ ░░░░░░░░░░░░ │ │ ░░░░░░░░░░░░ │
│ All consumed │ │ Available │ │ Available │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
▼ ▼ ▼
┌────┐ ┌────┐ ┌────┐
│API │ │API │ │API │
│ A │ │ B │ │ C │
│ ✗ │ │ ✓ │ │ ✓ │
└────┘ └────┘ └────┘
Exhausted Working Working
Thread Pool Bulkhead:
──────────────────────
Application
┌──────────────────────────────┐
│ │
│ ┌────────────────────────┐ │
│ │ Critical Operations │ │
│ │ Thread Pool (40) │ │
│ │ ████████████████ │ │
│ └────────────────────────┘ │
│ │
│ ┌────────────────────────┐ │
│ │ Normal Operations │ │
│ │ Thread Pool (30) │ │
│ │ ████████ │ │
│ └────────────────────────┘ │
│ │
│ ┌────────────────────────┐ │
│ │ Background Jobs │ │
│ │ Thread Pool (10) │ │
│ │ ████ │ │
│ └────────────────────────┘ │
│ │
└──────────────────────────────┘
Benefits:
• Critical ops always have resources
• Failure in one pool doesn't affect others
• Better resource allocation
• Predictable performance per service