Concurrency Control and Bulkhead Isolation
Bulkhead Pattern
A bulkhead isolates failures to prevent cascade. Ship hulls have bulkheads so one breach does not sink the entire ship. In systems, bulkheads are resource boundaries: separate thread pools, connection pools, or rate limits for different operations.
Without bulkheads, one slow dependency consumes all resources. A database going slow exhausts the thread pool. Now even requests that do not need the database cannot get a thread. The system appears completely down when only one component failed. Bulkheads contain the blast radius.
Implementing Bulkheads
Thread pool isolation: Dedicate separate thread pools to different operations. Critical operations get guaranteed capacity. If the recommendations thread pool exhausts, checkout still works. Size pools based on operation latency and throughput requirements.
Connection pool separation: Each downstream service gets its own connection pool. A slow service exhausts only its pool. Other services remain accessible. Monitor pool utilization to detect emerging problems before total exhaustion.
Semaphore limits: Cap concurrent operations with semaphores. Allow maximum 50 concurrent database queries regardless of available threads. Excess requests queue or reject immediately. Prevents overloading downstream systems.
Circuit Breaker Integration
Circuit breakers complement bulkheads. When a dependency fails repeatedly, the circuit opens and requests fail fast without consuming resources. After a timeout, the circuit allows trial requests. If they succeed, the circuit closes. If they fail, it reopens.
Combine with bulkheads: the bulkhead limits concurrent attempts, the circuit breaker stops attempts entirely when the dependency is known bad. Bulkheads protect your system from slow dependencies. Circuit breakers protect dependencies from being overwhelmed during recovery.