Learn
Lesson · Latency and the Tail · Budgets and limits

Latency Budgets

A budget is built from the objective downwards, not from the stages upwards. Take the SLO, subtract the floors that no code can remove — the light-speed minimum and the handshake round trips — and what is left is all the code may spend. Divide it among the stages and the arithmetic will usually tell you, immediately, that one stage cannot fit.

available = SLO − (light-speed floor + handshake round trips) even share = available ÷ number of stages residual per stage = share − that stage's own floor 400 − (56 + 152) = 192 ms available, 48 ms each across four stages search floors at 150 ms: residual −102 ms, and the plan is 26 ms short
Subtract the floors first; divide what is left

Core ideas

What this lesson establishes

The hard idea is the direction. A budget assembled by adding up what the stages currently cost is not a budget, it is a measurement with a total at the bottom.

1

Allocate backwards from the objective

Start with the number that was promised. Subtract everything that cannot be changed. Divide the remainder among the stages that can. A budget built the other way — adding stage costs upward — can only ever report what the system already does, which is the one thing a budget is not for.

2

The floors come out before anything is allocated

The light-speed minimum for the route and the sequential handshakes are fixed: 56 ms and 152 ms on the preset, 208 ms of a 400 ms objective. More than half the budget is gone before a line of code is considered, and pretending otherwise is how a plan that was never feasible gets approved.

3

A negative residual is the finding, not a failure of the method

The even share is 48 ms and search cannot run in less than 150 ms, so its residual is −102 ms. The other three stages release 76 ms between them against a need of 102 ms, leaving the plan 26 ms short. That arithmetic is the output: it names the stage, the amount, and the size of the gap that remains after every other stage has given up what it can.

The material

Building a budget from the top

What comes out first, what is left, and how to read a residual that has gone negative.

The objective on the lab’s preset is a p99 of 400 ms. The route has a light-speed floor of 56 ms — the New York to London figure from “The Speed-of-Light Floor”, rounded to the nearest millisecond — and the connection costs two sequential round trips at the measured 76 ms, which is 152 ms. Those two are not negotiable and they are subtracted before anything else happens.

SLO 400 ms − light-speed floor −56 ms − handshake round trips (2 × 76 ms) −152 ms ──────── available for the code 192 ms four stages, even share = 192 / 4 = 48 ms each stage floor share residual gateway 8 48 +40 fits auth 20 48 +28 fits search 150 48 −102 does not fit render 40 48 +8 fits ──────── floors total 218 192 − 218 = −26 ms spare +76 need 102 76 − 102 = −26 ms ✓

The two ways of counting the shortfall agree, which is the check the lab performs on every redraw: available minus the floors is −26 ms, and the surplus the fitting stages release minus the shortfall of the one that does not is also −26 ms. An allocation that does not balance both ways has an arithmetic error in it, and the panel says so when it happens.

Definition · Residual

A stage’s residual is its allocated share minus its own floor: the time it has left to spend on work that is not already forced. A positive residual is headroom the stage can release to another stage. A negative residual is a stage that cannot meet its allocation under any implementation, and the overall residual — available time minus the sum of the floors — says whether the whole plan is feasible.

Reading a plan that does not fit

The even split is a diagnostic, not a design. Nobody believes a gateway and a search engine deserve the same 48 ms; the split is there because it shows in one line which stage the objective cannot hold. Here it is search, by 102 ms, and the three other stages together have only 76 ms to give. Four things can be done and the arithmetic prices each of them.

  • raise the objective — at a 500 ms SLO the available time is 292 ms and the overall residual becomes +74 ms
  • remove a floor — dropping the two handshakes takes available to 344 ms and the residual to +126 ms
  • make search cheaper — at a 100 ms floor the plan has +24 ms overall, though search still exceeds an even share
  • take work off the critical path — which is the graph question of “Serial Sums, Parallel Maxes”, not a budgeting one

The third of those is worth pausing on. Cut search to a 100 ms floor and the overall residual turns positive at +24 ms, but search is still 52 ms above the even share of 48 ms and the lab still marks it as not fitting. Both statements are true and they mean different things: the plan is now feasible, and it is feasible only because the other three stages are subsidising the fourth. The even split is what makes that visible.

Example · Why the SLO has to be a percentile all the way down

If the objective is a p99, then every floor and every allocation in the table is a p99, and the stage figures cannot be means. A budget built by summing mean stage times will fit comfortably and be violated on most slow requests: on the stages of “Percentiles Do Not Add” the mean of the total is 26.36 ms and its p99 is 78 ms, a factor of three. Choosing the statistic is the first line of the budget, not an afterthought.

There is one more trap, and it is the one the previous lesson exists to prevent. Having filled in a p99 for every stage, it is natural to add them and compare the total with the objective. That total is not the p99 of anything. On the two stages of “Percentiles Do Not Add” it overstated by 41.0%, and on a different pair it would understate. A budget is a planning device built from per-stage allocations; the end-to-end percentile it implies has to be computed by convolution, and the two should be checked against each other rather than assumed equal.

Interactive

What the SLO leaves the code

Floors first, then the residual, then the stage that does not fit in it

A latency budget, allocated backwardsthe SLO, minus what physics takes, split across the stages that are left
fixed floorsfits its sharedoes not fit

Method

Laying out a budget

Top down, floors first, and the failing stage named rather than averaged away.

1

Write the objective and say which statistic it is

A p99 objective makes every number below it a p99. Mixing a percentile objective with mean stage figures produces a budget that fits on paper and fails in production, and it is the most common way for this exercise to go wrong before any arithmetic happens.

2

Subtract the floors that no implementation removes

The light-speed minimum for the route, and the sequential round trips the connection costs. On the preset that is 56 + 152 = 208 ms of a 400 ms objective — more than half — and what is left is the only part anybody gets to allocate.

3

Split what remains and compute each stage’s residual

An even split first, because it is the fastest way to find the stage the objective cannot hold. Residual is share minus the stage’s own floor; negative means impossible, not merely tight.

4

Balance the surplus against the shortfall, and check it twice

Add the positive residuals and the negative ones separately. Their difference must equal available time minus the total of the floors. If the two disagree, the arithmetic is wrong; if they agree and are negative, the plan is infeasible by exactly that much.

Allocating backwards

Score 0 / 0

A 400 ms p99 across four stages

The objective comes first and everything else is subtraction. The answer arrives before any stage has been optimised.

objective p99 ≤ 400 ms floors light-speed, NY–London 56 ms 2 round trips at 76 ms 152 ms ─────── 208 ms available 400 − 208 = 192 ms even share 192 / 4 = 48 ms gateway floor 8 residual 48 − 8 = +40 fits auth floor 20 residual 48 − 20 = +28 fits search floor 150 residual 48 − 150 = −102 DOES NOT FIT render floor 40 residual 48 − 40 = +8 fits check floors total 8 + 20 + 150 + 40 = 218 ms overall 192 − 218 = −26 ms spare 40 + 28 + 8 = 76, need 102 76 − 102 = −26 ms ✓ agrees verdict infeasible by 26 ms, and search is the stage

Nothing here required knowing anything about the code. Four floors, two fixed costs and one objective produced a verdict, the name of the stage responsible, and the exact size of the gap — which is the difference between “we should look at performance” and “search has to lose 26 ms or the objective has to move”.

The 208 ms of floors is the figure that most often surprises people. It is more than half the objective, it belongs to physics and protocol rather than to anyone’s code, and it is why a 400 ms promise on a transatlantic route is a much tighter promise than it sounds. Removing one of the two handshakes — a warm connection — is worth 76 ms, which is nearly three times what the whole plan is short by.

For a faded rehearsal, keep the four stages and set the objective to 350 ms with a 40 ms light-speed floor and one round trip of 76 ms instead of two. The supplied first move is the available time: 350 − 116 = 234 ms. Compute the even share, the four residuals, the spare and the need, and check the shortfall both ways. Say whether the plan fits and, if it does not, by how much — then reproduce all of it on the lab’s sliders before opening the quiz.

Common mistakes

1
Building the budget upward from what the stages currently costThat produces a total, not a budget. A budget is an allocation of a promised number, so it starts at the promise and works down; the useful output is the residual on each stage, and a plan assembled from the bottom has no residuals in it at all.
2
Budgeting in means when the objective is a percentileThe means are smaller, they add exactly, and they are about a different question. On the stages of “Percentiles Do Not Add” the mean total is 26.36 ms and the p99 is 78 ms. A budget filled in with means against a p99 objective understates the requirement by roughly a factor of three and will pass every review.
3
Leaving the fixed floors out, or discovering them lastOn the preset the light-speed minimum and the handshakes are 208 ms of a 400 ms objective. A plan that allocates the full 400 ms among the stages is over-committed by more than half before anyone writes anything, and the error is invisible because every individual stage figure is reasonable.

Check your understanding

✓
Finish when your first move on a latency target is a subtraction.

You should be able to take an objective, subtract the fixed floors, divide what remains, compute each stage’s residual, balance the surplus against the shortfall two ways, and state whether the plan is feasible and by how much it is not.

Note: The budget so far assumes every call eventually answers. It does not: a call has to be given up on at some point, and that decision has two consequences the budget has to hold. “Timeouts and Retries in the Budget” puts the worst case (r + 1) × T inside the allocation and prices the good calls the timeout throws away.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.