Terminology (6)Terms used in this lesson
Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.
- Work unit
- A measured amount of work, so requests of different cost can be added; here a receipt is 1 unit and a full return 5.
- Capacity
- The work per second a replica sustains while meeting its latency objective, from a load test with the same mix.
- Utilization
- Offered work divided by capacity.
- Headroom
- Capacity minus offered work; negative when the pool is over capacity.
- Saturation
- A replica or pool receiving more work than it completes, so its queue grows.
- Planning ceiling
- The utilization a team plans to stay under, leaving slack for bursts and latency.
Why this matters
A capacity check is a division, and most mistakes are in what goes into it: requests that cost different amounts, a pool average that hides one busy replica, and a ceiling that leaves no slack. Each one can approve a launch that the slowest users pay for.
This lesson assumes weighted sums, percentages and floor division.
What capacity and headroom measure
Capacity is a measured rate of work a system can serve under stated conditions. When request types cost different amounts, multiply each request rate by its work cost before adding. Dividing offered work by capacity gives utilization. Subtracting offered work from capacity leaves headroom in the same work units.
A pool total also needs a placement model: spare capacity on one replica may be unavailable to work pinned elsewhere. A planning ceiling reserves slack for variation, while saturation means a server cannot keep up with its offered work. The examples check pool and replica limits separately.
01Requests are not work
Requests are not work
A tax-filing site renders PDFs on six replicas. On deadline evening a change note counts 220 requests a second against a capacity of 360 and approves a button that adds 10 full returns a second. A full return costs five times as much to render as a receipt. Work out what the pool can really take.
Use a stable measured conversion between request types and work. Each replica was load-tested at 60 work units/s for this mix and latency objective: a receipt is 1 unit, a full return 5. The pool’s capacity is 6 × 60 = 360 units. Tonight’s 190 receipts and 30 full returns are 190 + 150 = 340 units, 94.44% of capacity, with 20 units of headroom.
const [replicas, perReplica] = [6, 60]; // work units per second each, from a load test
const mix = [
[190, 1],
[30, 5]
]; // receipts and full returns: requests per second, units each
const work = mix.reduce((sum, [rate, cost]) => sum + rate * cost, 0);
console.log(work, replicas * perReplica - work); // offered work and headroom
console.log(((85 / perReplica) * 100).toFixed(2)); // the busiest replica's share of its capacity
02The busiest replica
The busiest replica
| Replica | Load | Of 60 |
|---|---|---|
| 1 | 85 | 141.67% |
| 2 | 55 | 91.67% |
| 3–6 | 50 each | 83.33% |
Sticky routing keeps each filer on one replica, and the busiest gets 85 units a second against its 60. The pool’s 20 spare units sit on other replicas, where those filers cannot use them.
A Node.js process runs JavaScript on one thread; perf_hooks.monitorEventLoopDelay() can reveal event-loop delay from blocking work, GC or scheduling; it is not by itself a CPU-utilization measurement.
03The queue is already growing
The queue is already growing
In this fluid steady-rate illustration, the busy replica completes 60 and the other five complete their offered 55+4×50=255:315 units/s total while 340 arrive. The difference, 25 units a second, is a queue that grows by 1,500 units a minute. Utilization says how much is offered; completions say whether it is being served. Keep both: a pool under 100% can still have a growing queue when one member is saturated.
04How much more fits
How much more fits
Assume the new request stream is balanced perfectly in long-run work rate across six replicas; each request/s adds 5/6 units/s to each replica. Individual PDF jobs are not split into six pieces, so short-term placement and variability still need testing. Two limits apply: the pool must stay under the planning ceiling, and no replica may exceed its own capacity.
| Routing | Ceiling | Most extra |
|---|---|---|
| Sticky (busiest 85) | 100% | none |
| Even (57, 57, 57, 57, 56, 56) | 100% | 3 |
| Even | 80% | none |
With even routing the pool alone has room for ⌊20 / 5⌋ = 4, but 3 new requests/s add 2.5 units/s per replica and leave the busiest at 59.5. Four add 3.33 units/s and would put it above 60. With sticky routing nothing fits: the busiest replica is over before the launch. The 10-request/s button needs more than these modeled margins. Improve routing or capacity and repeat the measured-work check before approving it.
05Why plan below 100%
Why plan below 100%
06Decide on the launch tonight
Decide on the launch tonight
The launch report first needs weighted work rather than a raw request count. Sticky routing then makes the busiest replica a separate constraint. The last request combines that constraint with the chosen pool ceiling; a superficially sensible pool-headroom quotient still approves too many full returns.
A PDF render pool
Work and headroom, the busiest replica, then room for the launch.
In the frontend Back off from optional work in Next.js and Svelte Optional
Prefetching a PDF on hover is optional work. The first optional GET can discover the server’s utilization hint, then this tab pauses further prefetching at or above 80%, or when the hint is absent or invalid. It allows one optional request in flight and fetches the body; HEAD alone would not prefetch the PDF. This is local load reduction using a staleable hint, not cluster admission control or a guarantee about the busiest replica.
// Optional GET prefetches one PDF at a time; a server hint pauses this tab.
let busyUntil = 0;
let inFlight = false;
export async function prefetchReturnPdf(id: string): Promise<void> {
if (performance.now() < busyUntil || inFlight) return;
inFlight = true;
try {
const response = await fetch(`/api/returns/${encodeURIComponent(id)}/pdf`, {
method: "GET",
cache: "force-cache"
});
const raw = response.headers.get("x-pool-utilization");
const utilization = raw === null || raw.trim() === "" ? NaN : Number(raw);
if (
!response.ok ||
!Number.isFinite(utilization) ||
utilization < 0 ||
utilization >= 0.8
)
busyUntil = performance.now() + 60_000;
if (response.ok) await response.arrayBuffer(); // fetch the body, unlike HEAD
} catch {
busyUntil = performance.now() + 60_000;
} finally {
inFlight = false;
}
}
Check this idea later
Sources
Values above were computed in Node 22 and run in Go 1.27, Rust 1.99 and Apple clang 17. The render pool is a worked model.
Sign in to keep your read marks on every device. Sign in
Was this helpful?