Quick revision
The short answer
A semaphore bulkhead limits concurrent calls on the caller's own thread and costs almost nothing; a thread-pool bulkhead runs calls on a separate, bounded pool, which isolates the caller from a hung call and lets it stop waiting at a timeout, but costs threads, queues and context switches, and the hung call still occupies a pool thread. With virtual threads, a semaphore bulkhead plus proper client timeouts is usually enough, so I would make that the default and allow thread pools only for calls that cannot be timed out. Every bulkhead must publish active-call and rejection metrics, and its size must come from measured dependency capacity and be reviewed regularly.
What to remember
In this answer, we compared the two kinds of bulkhead. A semaphore bulkhead limits concurrency on the caller's thread with almost no overhead, while a thread-pool bulkhead moves calls to a dedicated pool so the caller can abandon a hung call, at the cost of threads, queues, context switches and a pool thread that stays stuck. With virtual threads, the semaphore bulkhead plus client timeouts is usually enough, so it becomes the default, with thread pools only for calls that cannot be timed out. Every bulkhead publishes active calls and rejections, and is sized from measured capacity and reviewed regularly.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A semaphore bulkhead limits concurrent calls on the caller's own thread and costs almost nothing; a thread-pool bulkhead runs calls on a separate, bounded pool, which isolates the caller from a hung call and lets it stop waiting at a timeout, but costs threads, queues and context switches, and the hung call still occupies a pool thread. With virtual threads, a semaphore bulkhead plus proper client timeouts is usually enough, so I would make that the default and allow thread pools only for calls that cannot be timed out. Every bulkhead must publish active-call and rejection metrics, and its size must come from measured dependency capacity and be reviewed regularly.
Why this question is asked
A bulkhead, named after the walls that divide a ship's hull into compartments, keeps one failing dependency from sinking the whole service. Without one, a slow payment provider can tie up every request thread, and pages that never touch payments stop working too. Choosing the kind of bulkhead used to be a real trade-off with platform threads; virtual threads change the balance. Interviewers ask this design question to see whether we can set one clear default for many teams and explain the exceptions. In this answer, we will recap both kinds, compare what each isolates and what it costs, see how virtual threads change the choice, and then define the standard, including metrics and sizing.
1A Quick Recap of the Two Kinds of Bulkhead
A semaphore bulkhead is a counter in front of a dependency. Before calling, the caller takes a permit; if none are free within a short wait, the call is rejected. The call itself runs on the caller's thread, so there is no hand-off and the overhead is a couple of atomic operations.
A thread-pool bulkhead gives each dependency its own small pool of threads and a bounded queue. The caller submits the call to that pool and waits for the result, usually through a future with a timeout. If the pool and queue are full, the call is rejected. Resilience4j offers both, as Bulkhead and ThreadPoolBulkhead; older Hystrix code used the thread-pool kind by default.
2What Each One Isolates, and What It Costs
The difference is about who gets stuck when a call hangs. With a semaphore bulkhead, the caller's thread is the one making the call, so if the dependency never answers and the client has no timeout, the caller is stuck too. The bulkhead still limits the damage, because only as many callers as there are permits can be stuck, but it cannot free them.
With a thread-pool bulkhead, the hung call occupies a pool thread, and the caller can stop waiting when its future times out. That is the real advantage: the caller can return an error at its deadline even if the underlying call never ends. But notice what really happened: the pool thread is still stuck, so after enough hangs the pool is full and every new call is rejected. Abandoning the wait isolates the caller, not the resource. The costs are also real: threads for every dependency, a queue to size, a context switch per call, and context such as the security context or trace IDs that must be copied to the pool thread.
| Aspect | Semaphore bulkhead | Thread-pool bulkhead |
|---|---|---|
| Where the call runs | caller's thread | dedicated pool thread |
| Overhead | almost none | hand-off, queue, context switch |
| Hung call without client timeout | caller is stuck | caller can give up; pool thread stays stuck |
| Context propagation | automatic, same thread | must copy MDC, security, tracing |
| Settings to size | max concurrent calls, max wait | core and max threads, queue capacity |
| With virtual threads | natural fit | mostly redundant |
3How Virtual Threads Change the Choice
The thread-pool bulkhead existed largely because platform threads were scarce. A Tomcat pool of 200 threads blocked on a slow dependency meant the whole service stopped, so moving slow calls onto their own small pool protected the precious request threads. With virtual threads, a blocked request thread costs only some heap, so a few hundred callers stuck on a slow dependency no longer starve the rest of the service. The semaphore already limits how many can be stuck at once.
What remains is the hung call that never ends, and the proper fix for that is a timeout in the client itself, connect and read timeouts on the HTTP client, a query timeout on JDBC, a request timeout on the gRPC stub. A client timeout actually ends the call and frees the connection, which neither kind of bulkhead can do. So the combination of a semaphore bulkhead, which limits concurrency, and client timeouts, which bound duration, covers both problems with no extra threads.
4The Standard I Would Define
The default for every outbound dependency would be a semaphore bulkhead with a short maximum wait, together with explicit client timeouts below the caller's own deadline. A thread-pool bulkhead is allowed only with a written reason, typically a library call that offers no timeout and cannot be interrupted, such as an old SDK, where abandoning the wait is the only protection we have. In that case the pool is small, its queue is bounded, and rejections are expected.
The standard also covers configuration. Each dependency has its own bulkhead, so one slow dependency cannot use another's budget. Settings live in configuration, not code, so they can be tuned without a release.
- Can the client enforce connect and read timeouts?HTTP, JDBC, gRPC usually canYesSemaphore bulkhead + client timeoutsNoContinue
- Can the call be interrupted or cancelled?YesSemaphore bulkhead + cancel at deadlineNoContinue
- Thread-pool bulkhead with a written reasonsmall pool, bounded queue, expect rejections
- Publish active calls and rejectionsfor every bulkhead, either kind
- Size from measured capacity, review quarterlyload tests and production metrics
5 steps in order. Play them, or step through them one at a time.
5Observability: Every Bulkhead Has Metrics
A bulkhead that nobody can see is a source of mysterious errors. Each one must publish at least the number of calls currently active, the configured maximum, and the number of rejections. Resilience4j publishes gauges for available and maximum concurrent calls through Micrometer and emits events for rejected calls; check your version for the exact names. With those, a dashboard can show that the payment bulkhead was full for ten minutes and rejected 4,000 calls, which instantly explains a wave of 503 responses. Alerts on the rejection rate catch both a struggling dependency and a limit that has become too small for normal traffic.
6Sizing From Measured Capacity
The size of a bulkhead should come from the dependency's capacity, not from a round number. Little's law gives the starting point: if the dependency serves 400 requests per second at a healthy 75 milliseconds, then 400 x 0.075 = 30 calls are in flight, and a limit of about 45 to 60 leaves headroom. With several instances, that budget is shared among them. These values drift as traffic and the dependency change, so I would ask teams to review them on a fixed schedule, for example each quarter, and whenever a load test or an incident shows them to be wrong. Some dependencies with highly variable capacity are better served by adaptive limits, which adjust from observed latency.
7Follow-up questions
Doesn't a thread-pool bulkhead give stronger isolation?
It isolates the caller's thread from a hung call, which mattered a lot when request threads were scarce. It does not free the resource that is hung, and with virtual threads the caller's thread is no longer scarce, so the extra isolation buys little. Client timeouts give the isolation that matters by actually ending the call.
How should rejections be handled?
Fast and visibly: map a full bulkhead to a clear error such as 503 with a retry hint, or to a fallback that does not call the same dependency. Never retry immediately into the same full bulkhead, since that only adds load.
Can a bulkhead and a circuit breaker work together?
Yes, and they complement each other. The bulkhead limits how many calls run at once; the circuit breaker stops calling a dependency for a while after a high failure rate. A common order is circuit breaker outside, bulkhead inside, so an open breaker rejects calls without even taking a permit.
8Conclusion
In this answer, we compared the two kinds of bulkhead. A semaphore bulkhead limits concurrency on the caller's thread with almost no overhead, while a thread-pool bulkhead moves calls to a dedicated pool so the caller can abandon a hung call, at the cost of threads, queues, context switches and a pool thread that stays stuck. With virtual threads, the semaphore bulkhead plus client timeouts is usually enough, so it becomes the default, with thread pools only for calls that cannot be timed out. Every bulkhead publishes active calls and rejections, and is sized from measured capacity and reviewed regularly.
Open with
I'd start from what each kind isolates. A semaphore bulkhead is just a permit count in front of a dependency: the call runs on the caller's thread, overhead is tiny, and context like tracing and security just works.
Then, if they want more
A thread-pool bulkhead runs the call on a dedicated small pool, so the caller can give up at a timeout even if the call hangs, but you pay for threads, a queue, context switches and context propagation, and the hung call still holds a pool thread. That trade-off made sense when request threads were scarce.
With virtual threads, a blocked caller costs some heap, not a platform thread, so the semaphore's limit on concurrency is enough, and the remaining problem, a call that never ends, is best solved with real client timeouts, which actually free the connection.
So my standard would be: a semaphore bulkhead per dependency plus connect and read timeouts below the caller's deadline as the default, and a thread-pool bulkhead only with a written reason, like an SDK that can't be timed out. Every bulkhead publishes active calls, the maximum and rejections, with alerts on rejection rate.
And sizes come from measured capacity, using Little's law as a starting point, reviewed every quarter or after an incident.
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.
- Official documentation
- java.util.concurrent, package documentation, JLS chapter 17, Threads and Locks
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 "Define how services should isolate calls to their dependencies: semaphore-based...": https://scrivio-interview-library.netlify.app/java/synchronizers/a295ce8960/