Skip to content

Spend a latency budget

11 min reading

Derive serial/parallel waiting and identify the measurement needed next

Page details

System Design · Follow a request

11 min reading · 24 min with practice

Sources

Published · Last edited:

Prerequisite: Follow a request through DNS, connections and HTTP. For basics, use the independent System Design foundations.

More
20px

Hypothetical scenario. Dev has the selected 290 ms cold-path total beside Maya’s 400 ms visitor deadline. He proposes a 400 ms timeout for every downstream operation so none is rushed. Priya covers the application part of the diagram and asks how much of the visitor’s allowance was already spent reaching it.

Maya: “The customer receives one deadline, not a new one at every service.”

Dev: “Then a child operation needs the time that remains when it actually starts.”

Priya: “And we still need enough time to return and present its result.”

This lesson refines the preceding request path without changing its workload. You will account for elapsed time, identify the work on the critical path and reserve a child allowance without counting the same headroom twice. The selected durations illustrate a budget; they are not observed latency claims.

Whose deadline are we spending?

A latency budget divides an end-to-end allowance among necessary activities. Its endpoint matters. Northwind promised an acceptable price presented to the visitor, so stopping the clock when an application sends headers would leave transfer and presentation unaccounted for. A server-side timeout can protect one component without satisfying that customer promise.

The earlier cold path allocated 20 ms to DNS, 60 ms to TCP setup, 60 ms to TLS setup, 80 ms to request and application waiting, 40 ms to transfer and 30 ms to presentation. These terms were deliberately non-overlapping. Their sum was 290 ms. The 110 ms difference from 400 ms was unallocated headroom, not permission for every component to add another 110 ms.

A timeout is a duration for an operation. A deadline identifies when the caller is no longer willing to wait. When work crosses a boundary, the child operation needs an allowance constrained by what remains of the parent’s deadline. Otherwise, a late-starting child may continue after its answer has stopped being useful.

Open the application term before optimizing it

For this hypothetical example, split the 80 ms term into 10 ms of ingress and dispatch, 20 ms of application preparation, a 40 ms product lookup and 10 ms of response assembly. The split adds to 10 + 20 + 40 + 10 = 80 ms. It describes serial work on this request; it does not assign universal timings to those operations.

Suppose Northwind also needs a stock annotation, independent of the product lookup after preparation. Choose 25 ms for that lookup. Before calculating, predict the outcome: must the visitor wait an extra 25 ms, or can some of that work overlap? The answer depends on the dependency graph, not the number of boxes in the architecture.

Parallel branches share a deadlineAfter ingress and preparation totaling thirty milliseconds, product work takes forty milliseconds while stock work takes twenty-five. Both are required before ten milliseconds of assembly. The application critical path is eighty milliseconds.Prepare30 msProduct40 msStock25 msAssemble10 ms
Count elapsed time along the required critical path. Resource work still occurs on both branches.

Calculate the tail of required fan-out

Hypothetical scenario. Extend the browsing experiment to twenty required, identically distributed lookups. Choose a 150 ms branch allowance and a 0.99 probability that each branch finishes within it. If completion events are independent, the probability that all twenty finish is 0.99²⁰, approximately 0.8179. About 18.21% of whole fan-outs therefore miss that branch allowance under this selected model. This is not a measured catalogue percentile.

Calculate the tail of required fan-out — selected design evidence
Budget fieldExampleOwner
Parent remaining190 ms at application entryCatalogue
Prepare / return reserve30 ms / 10 msCatalogue
Required branch phase150 ms maximumEach child receives remaining allowance
The two required replies share one branch phase; neither reply grants a fresh parent deadline.The two required replies share one branch phase; neither reply grants a fresh parent deadline. Catalogue to Product: 1 · remaining deadline; Catalogue to Stock: 2 · same parent allowance; Stock to Catalogue: 3 · stock reply; Product to Catalogue: 4 · product or deadline.CatalogueProductStock1 · remaining deadline2 · same parent allowance3 · stock reply4 · product or deadline
The two required replies share one branch phase; neither reply grants a fresh parent deadline. Enlarge the diagram to inspect its labels; the surrounding records and explanation give the text alternative.

A shared database stall breaks the independence assumption. Correlation changes the joint probability; marginal branch charts alone do not recover it. Record queue wait and execution separately on each branch and join them by parent request. Summing child p99 values still does not construct the parent's p99.

A hedge spends additional capacity to reduce waiting only when the duplicate has a useful chance of escaping the original delay. Choose a policy allowing at most one extra attempt on five of one hundred parents: one hundred primary attempts plus five duplicates is 105 attempts. Triggering a second copy on every slow request during shared overload can instead deepen the queue. Cancel abandoned work cooperatively and preserve the same operation identity if an effect is possible.

Parallel work changes waiting, not total work

If the application performs the two lookups serially, its chosen duration becomes 10 + 20 + 40 + 25 + 10 = 105 ms. Replacing the original 80 ms term increases the whole cold path to 290 − 80 + 105 = 315 ms. Headroom falls to 400 − 315 = 85 ms.

If both lookups begin together and both must finish, waiting for them takes the longer duration: max(40, 25) = 40 ms. The application path remains 10 + 20 + 40 + 10 = 80 ms, and the cold path remains 290 ms. This arithmetic assumes independent work and enough resources to execute concurrently. Parallel calls can still contend for connection pools or the same downstream store.

The stock branch is not free. Each catalogue read now makes two dependency calls instead of one. At the selected busy rate of fifteen reads per second, the dependency-call count is 15 × 2 = 30 per second. That count does not prove either dependency’s capacity. Reduced elapsed waiting and increased component work can occur together.

Give the child the remaining allowance

At the start of application waiting, the selected setup has consumed 20 + 60 + 60 = 140 ms. Reserving the chosen 40 ms transfer and 30 ms presentation leaves 400 − 140 − 40 − 30 = 190 ms for the application path. This is a planning allocation, not an instruction to transmit browser timing assumptions as trusted server configuration.

Ingress and preparation consume 30 ms of that allowance. Reserve the final 10 ms assembly. The parallel dependency phase therefore has at most 190 − 30 − 10 = 150 ms under this model. Giving each lookup a new 400 ms timeout would ignore both elapsed time and the reserved return path.

In an implementation using gRPC, explicit deadlines and propagation express this relationship. Its deadline guide distinguishes the caller’s willingness to wait from the work needed to stop on the server. Application activities must cooperate with cancellation; a cancelled call is not evidence that a separate effect was reversed.

A budget is not a percentile calculation

It is tempting to collect a high-percentile number for every component and add those numbers. That sum generally is not the corresponding percentile of whole-request duration. Different requests can experience the slowest stage, and stages may overlap or vary together. Keep observations attached to individual requests and measure the promised endpoint directly.

Northwind’s earlier sample required at least 190 acceptable results among 200 chosen attempts. A latency dashboard that excludes errors or missing client completions changes that denominator. Preserve failed and cancelled observations, and keep the freshness condition attached to the same result. A fast stale price still fails the combined acceptance rule.

In the wild: propagation is part of the contract

The gRPC documentation describes propagating deadlines into downstream calls, accounting for elapsed time. This is a real implementation mechanism Northwind can investigate. It supports a bounded-wait design; it does not certify the selected 150 ms allowance or show that the catalogue meets its user target. Those require evidence from the declared workload and client conditions.

Hypothetical failure scenario. A product lookup stalls. The catalogue stops waiting, but the dependency keeps processing abandoned requests. New requests compete with work whose answers can no longer arrive in time. Simply shortening the outer timeout makes the dashboard look quicker while useful completion deteriorates. Cancellation cooperation, bounded admission and downstream measurements address different parts of this failure.

Optimize the term that constrains the decision

Use this budget when the required path is known and you need to decide where to measure or spend engineering effort. If connection setup dominates cold requests, optimizing response assembly alone cannot remove that setup. If one required dependency dominates the parallel section, accelerating the already faster branch does not shorten the selected critical path.

Do not parallelize work whose second action depends on the first result. Nor should a latency target silently make required content optional. A stock annotation can be omitted only if the product contract permits that degradation and the displayed result remains honest. Record that product choice separately from the scheduling choice.

Northwind now has a budget with named reservations and a reason to trace dependency waits. The next question is where those requests should execute. Several workers help only when traffic reaches healthy capacity without creating a new queue or concentrating long requests on one instance.

Challenge the proposed mechanism

Both dependencies report p99 below 150 ms. Can the review approve the whole fan-out target?

Reveal the design reasoning

No. Obtain joined outcomes for the declared population, including missing and cancelled replies. The independence calculation is a model to challenge, not a substitute for observations. Approve a hedge only with a duplicate-work budget and evidence that another replica avoids the relevant delay.

Decision and reconsideration: Keep the shared deadline; admit hedges within a separate work budget. Reconsider when joined branch observations show a different dependency structure.

Test the budget

  1. The stock lookup takes 25 ms. Does parallelizing it always save 25 ms?

    Check dependencies and contention

    Only in the selected independent, sufficiently resourced example does serial waiting fall from 105 to 80 ms. A lookup that needs the product result cannot start simultaneously, and shared-resource contention can change both durations.

  2. A child starts after 30 ms of the 190 ms application allowance. May it wait 190 ms?

    Keep the return reservation

    No. With 10 ms still reserved for assembly, the child phase has 190 − 30 − 10 = 150 ms. Starting a fresh full allowance spends time the parent no longer has.

  3. Every server’s latency chart improves after an outer timeout is shortened. Is the customer goal met?

    Count outcomes through presentation

    Not necessarily. More requests may be failing or disappearing from the measured population. Evaluate the original attempts and their jointly fast, fresh results at the promised endpoint.

A deadline tells Northwind when a reply ceases to be useful. It does not ensure that a request reaches a worker able to meet it. Page 07 takes the workers from the capacity estimate and makes their eligibility and routing decisions explicit.

Northwind decision log

Reserve setup, return and presentation time before assigning child allowances.
Measure the required critical path and the total dependency work separately.
Carry the 400 ms endpoint and observed completion population into the routing design.

Go deeper: elapsed time and bounded waiting