Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

Services in your platform each call several dependencies through one shared pool, and a slow dependency regularly exhausts the pool and takes down unrelated features. What isolation and sizing standard would you introduce?

I would introduce bulkheads: every dependency gets its own concurrency limit, through a separate pool or a semaphore, so a slow dependency can only use up its own share. Each limit is sized from that dependency's rate, latency and capacity, each dependency has its own timeout and circuit breaker so it fails fast, and with virtual threads the limits become per-dependency semaphores. The whole standard ships in a shared client library that publishes metrics per dependency.

Why this question is asked

A shared pool looks efficient: one set of threads serves every outgoing call. But it couples features that have nothing to do with each other. When the recommendation service slows down, every thread ends up waiting on it, and suddenly checkout fails too. Interviewers ask this design question because isolation is one of the main tools for keeping a partial failure partial. In this answer, we will see exactly how a shared pool spreads the failure, introduce bulkheads, size them with real numbers, add per-dependency timeouts and circuit breakers, adapt the design to virtual threads, and package it so every team gets it by default.

1How One Slow Dependency Takes Everything Down

Suppose a service has one pool of 100 threads for all outgoing calls, to inventory, pricing and recommendations. Normally each call takes 20 to 200 ms, and the pool is mostly idle. Now recommendations slows to 10 seconds per call. Every recommendation call holds a thread for 10 seconds, so after a few seconds of traffic, all 100 threads are inside recommendation calls. Inventory and pricing calls, which are still fast, wait in the queue behind them or are rejected. Checkout, which needs pricing, fails, although pricing itself is perfectly healthy.

The name for the fix comes from ships. A ship's hull is divided by walls called bulkheads, so a leak floods one compartment instead of sinking the whole ship. In software, a bulkhead is a separate limit for each dependency.

A shared pool of 100 threads during the slowdown
DependencyNormal latencyThreads it holdsEffect
Recommendations200 ms -> 10 s100 (all of them)slow, as expected
Pricing50 ms0, waiting in queuecheckout fails
Inventory20 ms0, waiting in queueproduct pages fail

2Bulkheads: A Separate Limit per Dependency

With bulkheads, each dependency gets its own concurrency limit. On platform threads, the simplest form is a separate pool per dependency; another is one shared pool with a semaphore per dependency, a counter of permits that each call must take before it starts. Either way, when recommendations slows down, it can only fill its own 30 permits. Further recommendation calls are rejected at once and that feature degrades, for example by showing no recommendations, while pricing and inventory keep their own capacity.

Java
BulkheadConfig recConfig = BulkheadConfig.custom()
.maxConcurrentCalls(30) // at most 30 recommendation calls at once
.maxWaitDuration(Duration.ofMillis(10)) // wait 10 ms for a permit, then reject
.build();
Bulkhead recommendations = Bulkhead.of("recommendations", recConfig);
List<Product> recs = Try.ofSupplier(
Bulkhead.decorateSupplier(recommendations, () -> recClient.forUser(userId)))
.recover(BulkheadFullException.class, e -> List.of()) // full: show no recommendations
.get();

This example uses Resilience4j, whose Bulkhead is semaphore-based and whose ThreadPoolBulkhead is the separate-pool form. Notice that the rejection is fast and has a planned fallback. That is the point of a bulkhead: when a compartment is full, the answer is an immediate, designed degradation, not a queue.

3Sizing Each Limit From Rate, Latency and Capacity

Each limit comes from Little's law for that dependency: calls in flight equal calls per second times seconds per call. We take the peak rate and a high-percentile latency, add headroom, and then cap the result at what the dependency itself can take, such as its own concurrency limit or our share of it.

Sizing bulkheads per instance
DependencyPeak rate x p99 latencyIn flightLimit chosen (cap)
Inventory300/s x 0.04 s1220
Pricing200/s x 0.10 s2030 (its share of capacity)
Recommendations100/s x 0.25 s2530
Little's law gives the need; the dependency's capacity sets the ceiling.

Notice the last column. The limit is not just a guess about our own needs; it also protects the dependency. If pricing can only handle 40 concurrent calls from all our instances, our limit per instance must respect that share. A slow dependency then sees a steady, bounded load from us instead of a surge of retries and queued calls.

4Timeouts and Circuit Breakers per Dependency

A bulkhead limits how many threads a slow dependency can hold, but each held thread is still stuck until the call ends. So every dependency also gets its own timeout, set from its own latency profile: inventory might get 200 ms, recommendations 500 ms. A shared timeout is always wrong for someone, either too long for the fast dependency or too short for the slow one.

Each dependency also gets its own circuit breaker. When the recent failure or slow-call rate passes a threshold, the breaker opens and calls fail immediately for a few seconds, which frees the bulkhead's permits at once and gives the dependency room to recover. The order of protection on each call is: circuit breaker first, which may reject without doing anything, then the bulkhead, then the call with its timeout.

Step throughOne outgoing call through the shared client
  1. Circuit breaker for this dependency open?recent failures or slow calls
    YesFallback at onceNoTake a permit
  2. Permit free in this dependency's bulkhead?e.g. 30 for recommendations
    YesMake the callNoFallback at once
  3. Call with this dependency's timeoute.g. 500 ms
  4. Record result and latencymetrics tagged with the dependency name

4 steps in order. Play them, or step through them one at a time.

Each dependency fails in its own compartment.

5Bulkheads With Virtual Threads

With virtual threads, each request can run on its own cheap thread, so there is no shared pool to exhaust and no reason to keep separate pools. But the coupling problem does not disappear: without limits, a slow dependency now collects thousands of waiting virtual threads, plus their memory and connections, and the dependency receives an unbounded number of calls.

So the standard says that on virtual threads, a bulkhead is a semaphore per dependency, sized exactly as before. The semaphore is the compartment wall; the threads themselves are free. This is also simpler than separate pools, because a semaphore holds no threads of its own.

Java
Semaphore pricingPermits = new Semaphore(30);
Price price(String sku) throws InterruptedException {
if (!pricingPermits.tryAcquire(10, TimeUnit.MILLISECONDS)) throw new DependencyBusyException("pricing");
try {
return pricingClient.get(sku); // blocking call on a virtual thread, with its own timeout
} finally {
pricingPermits.release();
}
}

6Shipping It as a Shared Client Library

A standard that each team rebuilds by hand will drift. So the platform provides a client library where each dependency is declared once in configuration, with its limit, wait time, timeout and circuit breaker settings, and every outgoing call goes through it. The library applies the protections in the right order and publishes metrics tagged with the dependency name: permits in use, rejections, timeouts, circuit breaker state and latency. A dashboard per service then shows at a glance which dependency is saturated.

Defaults matter as much as features. A new dependency added without configuration gets a conservative limit and timeout and a warning in the logs, never the unlimited behaviour of a shared pool.

7Follow-up questions

Separate pools or semaphores on platform threads, which would you choose?

Semaphores are lighter and keep the caller's thread, so context such as transactions and tracing stays in place. Separate pools additionally let the caller time out while the call continues on another thread, which helps with libraries that ignore timeouts. I would default to semaphores and use a separate pool only for dependencies whose clients cannot be timed out reliably.

Does a bulkhead waste capacity when the other dependencies are idle?

Somewhat, because a permit for inventory cannot be used by pricing. But permits on a semaphore cost nothing while unused, and the point is predictable failure, not maximum sharing. If the sums are too tight, we raise individual limits based on metrics.

How do you choose the fallback when a bulkhead is full?

From the feature's importance. Optional features return an empty result or a cached value; important ones fail the request with a clear 503 so the client can retry. The decision is made per dependency and written into the client configuration.

8Conclusion

In this answer, we saw how one slow dependency fills a shared pool and takes down unrelated features, and introduced bulkheads, a separate concurrency limit per dependency through pools or semaphores. Each limit is sized by Little's law from that dependency's rate and latency and capped by its capacity, each dependency has its own timeout and circuit breaker so it fails fast, virtual threads replace pools with per-dependency semaphores, and a shared client library makes all of this the default, with metrics per dependency.

What to say in the interviewAbout 90 seconds aloud

Open with

The root problem is that one shared pool couples unrelated features: when one dependency slows to seconds per call, it collects every thread, and calls to healthy dependencies wait behind it.

Then, if they want more

So my standard is bulkheads, a separate concurrency limit for each dependency. On platform threads that can be a separate pool per dependency or a semaphore per dependency; when recommendations is slow it can only fill its own permits, further calls are rejected immediately with a planned fallback, and pricing and inventory keep their capacity.

Each limit is sized from that dependency's numbers with Little's law, peak rate times high-percentile latency plus headroom, and capped at what the dependency can actually take, our share of its capacity.

On top of that, each dependency gets its own timeout from its own latency profile, because one shared timeout is wrong for someone, and its own circuit breaker, so a failing dependency fails fast and frees its permits.

With virtual threads there is no pool to exhaust, but the coupling and the load on the dependency remain, so the bulkhead becomes a semaphore per dependency with the same sizing.

I would deliver all of it in a shared client library: dependencies are declared in configuration, every call goes through breaker, bulkhead and timeout in that order, undeclared dependencies get conservative defaults, and metrics are tagged per dependency so dashboards show which one is saturated.

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 "Services in your platform each call several dependencies through one shared pool, and a...": https://scrivio-interview-library.netlify.app/java/executors/78165fa7e4/