What is the Bulkhead pattern, and how does it prevent system-wide failures?

The Bulkhead pattern isolates resources for different parts of a system, named after the watertight compartments in a ship's hull, so that a failure or overload in one area cannot spread and sink the whole system.

Key Points: • Each dependency or service call is allocated its own dedicated pool of resources — such as a separate thread pool or connection pool — rather than sharing one pool across everything. • If one dependency becomes slow or starts failing, only the resources allocated to it are exhausted; calls to other dependencies continue unaffected. • Without bulkheads, a single slow dependency can consume all available threads in a shared pool, indirectly blocking requests to completely unrelated, healthy services. • Bulkheads are commonly implemented with Resilience4j's ThreadPoolBulkhead or SemaphoreBulkhead in Spring Boot applications. • It's a complementary pattern to Circuit Breaker — bulkheads limit how much of the system a failure can consume, while circuit breakers stop calling the failing dependency altogether.

Example: If a Recommendation Service call starts hanging for 30 seconds each, a bulkhead limiting it to its own pool of 10 threads ensures the Order and Payment services, which use separate thread pools, keep responding normally instead of all requests stalling together.

Code Example:

@Bulkhead(name = "recommendationService", type = Bulkhead.Type.THREADPOOL)
public List<Product> getRecommendations(String userId) {
    return recommendationClient.fetch(userId);
}

Interview Tip: A concise interview answer is:

"The Bulkhead pattern gives each dependency its own isolated pool of resources, like a dedicated thread pool, so that if one dependency becomes slow or fails, it can only exhaust its own allocated resources instead of starving requests to unrelated, healthy services. It's what stops a single failing component from taking down the entire system."