Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

What is the bulkhead pattern? Compare Resilience4j's semaphore bulkhead with its thread pool bulkhead.

A bulkhead limits how much of our resources one dependency or function can use, so when that dependency fails or slows down, it cannot exhaust everything else. Resilience4j's semaphore bulkhead limits the number of concurrent calls on the caller's own thread, making extra calls wait up to maxWaitDuration or rejecting them. Its thread pool bulkhead runs calls on a dedicated pool with a bounded queue and returns a CompletableFuture, which isolates more strongly but adds thread switching and the need to propagate context.

Why this question is asked

Most cascading failures follow the same story: one slow dependency quietly takes every thread or connection in a service, and then requests that have nothing to do with that dependency start failing too. The bulkhead pattern exists to stop that. Interviewers ask about it, and about the two Resilience4j flavours, to see whether we understand what resource we are protecting and what each option costs. In this answer, we will recap where the name comes from, see the semaphore bulkhead and the thread pool bulkhead in code, compare them side by side, and see why separate connection pools are bulkheads too.

1A Quick Recap of the Bulkhead Idea

A ship's hull is divided into watertight compartments called bulkheads. If the hull is breached, only one compartment floods and the ship stays afloat. In software, the compartments are shares of a limited resource, usually threads or connections, and each dependency or function gets its own share.

Without a bulkhead, a service with 200 request threads lets any dependency use all 200. If the reporting API slows from 100 ms to 10 seconds, requests to it pile up until every thread is waiting on reporting, and requests for payments or search, which would be fast, have no thread left. With a bulkhead that allows reporting only 20 concurrent calls, the other 180 threads stay free and only reporting degrades.

2The Semaphore Bulkhead

A semaphore is a counter of permits. Resilience4j's semaphore bulkhead holds maxConcurrentCalls permits (25 by default). Each call takes a permit before it runs and gives it back when it finishes. The call runs on the caller's own thread, so there is no extra thread and no hand-off. When all permits are taken, a new call waits for up to maxWaitDuration (0 by default, meaning reject immediately) and then fails with BulkheadFullException.

Java
resilience4j:
bulkhead:
instances:
reporting:
max-concurrent-calls: 20
max-wait-duration: 0ms
@Bulkhead(name = "reporting") // type defaults to SEMAPHORE
public Report report(String id) { return reportingClient.fetch(id); }
// 20 calls in flight -> the 21st throws BulkheadFullException at once

Notice that the semaphore bulkhead cannot stop a call that has already started. If a call hangs, it holds its permit until it returns, so a semaphore bulkhead must always be paired with a timeout on the client. Its strength is its low cost: it adds almost nothing to each call, and it works the same with platform threads, virtual threads or reactive code.

3The Thread Pool Bulkhead

The thread pool bulkhead gives the dependency its own small pool of threads with a bounded queue. The caller submits the call and immediately gets a CompletableFuture back. The call runs on one of the bulkhead's threads. If all threads are busy and the queue is full, the submission is rejected with BulkheadFullException. Settings include maxThreadPoolSize, coreThreadPoolSize and queueCapacity (100 by default); check your version for the exact defaults.

Java
resilience4j:
thread-pool-bulkhead:
instances:
reporting:
max-thread-pool-size: 10
core-thread-pool-size: 5
queue-capacity: 20
@Bulkhead(name = "reporting", type = Bulkhead.Type.THREADPOOL)
public CompletableFuture<Report> report(String id) {
return CompletableFuture.completedFuture(reportingClient.fetch(id));
}
// 10 running + 20 queued -> the 31st call fails with BulkheadFullException

The method must return a CompletableFuture (or CompletionStage), because the work really happens on another thread. The isolation is stronger: the caller's thread is free at once and can wait on the future with its own timeout, so even a hung call does not hold a request thread. But there is a cost. Each call is handed between threads, which adds context switching, and anything stored in ThreadLocal variables on the caller's thread, such as the logging MDC, the Spring Security context or the tracing span, is not visible on the pool thread unless we propagate it. Resilience4j provides ContextPropagator for this, and Micrometer's context propagation library helps with tracing.

4Comparing the Two

The choice comes down to what we need to isolate and how much overhead we accept. For most synchronous Spring MVC services, a semaphore bulkhead with a strict client timeout is enough and much simpler. The thread pool bulkhead is worth it when we need the caller to stop waiting no matter what the dependency does, or when we already work with futures.

Semaphore bulkhead vs thread pool bulkhead
AspectSemaphoreThread pool
Runs the call onthe caller's threada dedicated pool thread
Return typeanythingCompletableFuture or CompletionStage
Limitmax-concurrent-callsthreads plus queue-capacity
When fullwait max-wait-duration, then rejectreject when queue is full
Hung callholds a permit and the callerholds a pool thread only
Overheadalmost nonethread hand-off, context propagation
Virtual threadsworks welladds little value

5Connection Pools Are Bulkheads Too

Threads are not the only shared resource. If all outgoing HTTP calls share one connection pool with 50 connections, a slow dependency can hold all 50, and calls to other dependencies wait for a connection. The same is true for database pools: a reporting query and a checkout query sharing one HikariCP pool compete for the same connections.

Giving each dependency its own HTTP connection pool, with its own maximum size and acquisition timeout, and giving heavy workloads their own database pool, applies the bulkhead idea without any library at all. In practice, we combine both: a concurrency limit in front of the dependency and a separate pool behind it.

6Follow-up questions

What size should a bulkhead be?

We can estimate it with Little's law: concurrent calls equal the arrival rate times the duration. If reporting gets 20 requests per second and normally takes 200 ms, about 4 calls are in flight, so a limit of 10 to 20 leaves headroom for spikes while still protecting the rest of the service when reporting slows down.

What should happen when the bulkhead rejects a call?

The rejection is fast, so we turn it into a quick degraded response: a fallback with cached data, an empty section, or a 503 with Retry-After. That is the whole point: fail fast for the overloaded dependency instead of making everyone wait.

Is a bulkhead the same as a rate limiter?

No. A rate limiter limits how many calls start per unit of time, such as 100 per second. A bulkhead limits how many calls are in progress at once. A slow dependency at 10 calls per second can still exhaust threads if each call takes 30 seconds, which only a bulkhead catches.

7Conclusion

In this answer, we saw that a bulkhead divides a limited resource so one failing dependency cannot take it all. Resilience4j's semaphore bulkhead counts concurrent calls on the caller's thread and is cheap but needs a timeout, while the thread pool bulkhead runs calls on its own pool with a queue and returns a CompletableFuture, isolating better at the cost of thread switching and context propagation. Separate connection pools per dependency are bulkheads too.

What to say in the interviewAbout 90 seconds aloud

Open with

A bulkhead limits how much of a shared resource one dependency or feature can take, so its failure stays contained, like compartments in a ship. The classic case is a slow dependency eating every request thread, so unrelated fast requests start failing too.

Then, if they want more

Resilience4j has two kinds. The semaphore bulkhead keeps a count of permits, max-concurrent-calls, twenty-five by default, and runs the call on the caller's own thread. If no permit is free, the call waits up to max-wait-duration, zero by default, and then gets BulkheadFullException.

It costs almost nothing and works with virtual threads, but a hung call keeps its permit and its caller, so it must be paired with a client timeout. The thread pool bulkhead runs the call on a dedicated small pool with a bounded queue and returns a CompletableFuture.

That isolates more strongly, because the caller's thread is free and can wait with its own timeout, but it adds a thread hand-off and I have to propagate context like the MDC, the security context and tracing, which Resilience4j's ContextPropagator helps with. For most Spring MVC services I would use the semaphore one plus timeouts.

I would also point out that separate HTTP connection pools per dependency and separate database pools for heavy work are bulkheads too, and I size limits with Little's law: arrival rate times duration.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is the bulkhead pattern? Compare Resilience4j's semaphore bulkhead with its thread...": https://scrivio-interview-library.netlify.app/spring-boot/resilience/5bae56a1f7/