What a bulkhead does when one service gets slow
One client talks to two services. payments is fast. search gets slow at 6 s and is fixed at 20 s. Both clients send the same traffic. In each client, payments and search share one global limit.
Only the right client also gives search its own partition limit. Retries are off here, so each box is one request. Press Play. The page slows down at key moments and says what happened.
QueueFullErrorWith a search partition limit
search: concurrency 3, limitFirstAttempts; maxRetries: 0How long each payments request waited to start
Each point is one payments request, and it is placed where the request started. A red ring on the top line marks a request rejected by a full queue; the mark inside shows its lane: a square for global only, a circle for the search limit. Waiting here means waiting for a global permit.
Global permits held by search
The dashed line is the global limit. Without a partition limit, search can take every permit. With one, it stops at its own number of slots.
What the bulkhead gives you
- Search cannot take every permit. Search holds at most as many permits as it has slots. With this page's defaults, 3 slots and 8 permits, payments always has the other 5.
- The overflow waits in search's own queue. A search request in that queue holds no global permit. It does not block the global queue that payments uses.
- Only search sees the errors. When the search queue is full, new search requests fail at once with
QueueFullErrorandscope: "partition". Payments keeps working.
What it costs
- Search gets worse. Its requests wait longer and more of them fail. The bulkhead moves the pain to the slow service. It does not fix it.
- It counts requests that run at the same time. It does not limit requests per second. A rate limit does that.
- Queued requests have no wait limit of their own. Set
timeout.totalMsif you want them to give up. - By default the bulkhead skips first attempts. Without
limitFirstAttempts: true, only the global limit applies, as in the left lane. The partition limit always applies to retries.
What is not limited: payments has no limit of its own here, so it can still use every free global permit.
If many partitions get slow at once, they can still fill the global queue together. A partition limit only helps when it is smaller than the global limit.
In Vereda
There are two limits. The global semaphore (src/queue/semaphore.ts) counts every attempt in the client.
The partition bulkhead (src/queue/bulkhead.ts) counts attempts in one partition. A partition is the host unless you set partition on the request.
With limitFirstAttempts: true, an attempt takes a partition slot first and then a global permit (src/core/client.ts). The slot stays taken while it waits for the permit.
A full queue gives QueueFullError, with scope: "global" or "partition". Retries in src/queue/retry.ts always use both limits.
Defaults: 50 permits and 100 queued globally, 5 slots and 100 queued per partition. Here the numbers are smaller so the effect is easy to see.
A test (test/demos/bulkhead.parity.test.ts) runs this page's model against the real HttpClient, request by request, so the page has to change when the library does.
