Video in progress
What is the bulkhead pattern?
A bulkhead splits resources (threads, connections) into separate compartments for different dependencies. That way one slow service can't take all the threads and stop everything else.
📖 Answer
The name comes from the partitions in a ship: if water gets into one compartment, the ship doesn't sink, because the other compartments are sealed.
The problem: order-service calls three services, payment, catalog and delivery. They all use one shared thread pool. delivery slows down and takes all the threads. Now neither payments nor the catalog work, even though they're healthy.
With a bulkhead, you put a limit on each dependency:
resilience4j:
bulkhead:
instances:
delivery:
max-concurrent-calls: 20
max-wait-duration: 0
@Bulkhead(name = "delivery")
public DeliveryQuote quote(Address address) {
return deliveryClient.quote(address);
}
Now no more than 20 calls to delivery can be in flight at once; the 21st is rejected immediately, and the remaining threads stay free for other work.
Resilience4j has two kinds: semaphore-based (the @Bulkhead default) and one with a separate thread pool (ThreadPoolBulkhead).
Sign up to mark studied questions and save your progress.