Spring / Resilience4j Interview questions
Which is better and why: SemaphoreBulkhead or ThreadPoolBulkhead?
Neither is universally "better" - they suit different situations, and the choice mostly comes down to whether the protected call is synchronous/blocking or needs true interruption on timeout.
SemaphoreBulkhead is lighter weight: it limits concurrency using a plain semaphore on the caller's own thread, with no thread hand-off overhead, which makes it the better fit for fast, blocking calls where you just want to cap concurrency cheaply.
ThreadPoolBulkhead runs calls on a separate, bounded pool and returns a CompletionStage, which costs more overhead per call but has a real advantage: because the call runs on its own thread, it can actually be interrupted, which is what makes it the only option that pairs meaningfully with TimeLimiter to enforce a hard timeout on a call that would otherwise hang indefinitely.
In practice, teams default to SemaphoreBulkhead for most calls and reach for ThreadPoolBulkhead specifically when a hard timeout on an otherwise-uninterruptible call is a real requirement.
More Related questions...