What is the Bulkhead pattern?
Topic: microservices, Resilience. Level: Intermediate.
Answer
Named after ship compartments, the bulkhead pattern isolates resources (thread pools, connection pools, semaphores) per dependency so a failure in one cannot consume all resources and sink the whole service. If calls to a slow `report-service` are capped at their own pool, they can't starve threads needed for `payment-service`. It contains partial failures and preserves capacity for healthy paths.
```java
// Separate, bounded pools per dependency — one can't exhaust the other
Bulkhead paymentBh = Bulkhead.of("payment",
BulkheadConfig.custom().maxConcurrentCalls(20).maxWaitDuration(Duration.ofMillis(50)).build());
Bulkhead reportBh = Bulkhead.of("report",
BulkheadConfig.custom().maxConcurrentCalls(5).build()); // slow, so cap tight
Supplier<Reply> call = Bulkhead.decorateSupplier(paymentBh, () -> paymentClient.charge(req));
```