Skip to content

    System Design

    Tail Latency and p99: Why Averages Lie

    What p99 measures, why a fan-out turns rare slow calls into common slow requests, how to measure tails honestly, and which mitigations are worth their cost.

    By Published 13 min read

    Share

    Standard lessonintermediateInteractive simulatorBackend System Design

    Before this: Little's Law and Queueing Intuition

    What you'll learn: By the end of this lesson you will be able to say what a percentile such as p99 measures and where tail latency comes from, work out how fan-out turns a rare slow call into a common slow request, measure tails without the three classic mistakes (averaging percentiles, coarse buckets, coordinated omission), choose among hedged requests, deadlines, good-enough responses and load shedding, and run a small seeded model that shows each effect with numbers.

    A restaurant reports an average wait of 12 minutes. Most parties sit within ten, and one in fifty waits an hour because a large booking blocked the room. The average is true and describes nobody's evening; the bad reviews come from the one in fifty.

    That is tail latency. The latency and throughput lesson defined percentiles and showed the queueing curve. This lesson covers why the slow 1 percent exists, why a service that calls many others meets it constantly, how to measure it honestly, and what to do about it. The Little's law and queueing lesson in the same module is assumed, not repeated.

    Verified on 2026-12-02 against the Tail at Scale paper, the Google SRE book, the Prometheus and gRPC documentation and the HdrHistogram Javadoc. The lab on this page was run; its output is embedded byte for byte. Every latency in it is invented.

    The core idea

    A percentile is a position in the sorted list of timings, and the tail is everything beyond a position you care about. The mean describes the middle; the p99 describes the unluckiest one request in a hundred. In a system that calls other systems, that request is far more common than 1 percent.

    Three illustrations run through the lesson, each labelled:

    • Minimal example: one call that is fast 98 percent of the time and slow 2 percent of the time, so the mean looks healthy and p99 does not.
    • Realistic example: ShopStream's product page, which calls five services in parallel.
    • Failure example: a load test whose own method hides a two-second stall from its report.

    What the tail is and where it comes from

    Nearest-rank percentiles (the method used throughout): sort n timings and take the one at position ceil(p / 100 x n). With 1,000 timings, p99 is the 990th. As a rule of thumb, a p99 needs many more than 100 samples in its window and a p99.9 many more than 1,000.

    Tails are not a bug in one component. The Tail at Scale paper lists causes present in almost every deployment: shared resources, background daemons that "generate multi-millisecond hiccups", global resources such as network switches, maintenance activities such as log compaction and garbage collection, and queueing in "multiple layers" that amplifies the rest. Its position is practical: eliminating all variability is infeasible, so build to tolerate it.

    On a JVM service the list shows up as garbage collection pauses, waits for a pooled connection, time in a thread pool queue and retries after a timeout: places where a request waits for something other than its own work.

    Fan-out: when the tail becomes the median

    A request that fans out to many backends and waits for all of them is as slow as its slowest call. If each call has probability q of being slow, the chance that at least one of n calls is slow is 1 - (1 - q)^n.

    The paper's example: if each server has a 99th-percentile latency of one second, a request that needs one server is slow one time in 100, but a request that must collect responses from 100 such servers in parallel is slow 63 percent of the time. With one-in-10,000 slow calls and 2,000 servers, almost one request in five is slow.

    Realistic example (ShopStream, all numbers illustrative). The product page waits on five calls: catalogue, price, stock, recommendations and reviews. Suppose each is slower than its own p99 on 1 percent of calls. Then the page is slow on 1 - 0.99^5 = 4.9 percent of views, almost five times the per-call rate.

    ShopStream product page fan-out to five servicesShoppers to Product page (page view); Product page to Catalogue (parallel); Product page to Price; Product page to Stock; Product page to Suggestions; Product page to ReviewsShoppersShoppersProduct page: waits for allProduct pagewaits for allCatalogueCataloguePricePriceStockStockSuggestionsSuggestionsReviewsReviewspage viewparallel

    Figure 1. A fan-out of five. How to read this: the page cannot finish until the slowest of the five answers. Each leaf's slow 1 percent is now a 4.9 percent chance for the page.

    Measuring a tail honestly

    Three mistakes account for most wrong tail numbers.

    Averaging percentiles

    You cannot average per-server percentiles to get a fleet percentile. The Prometheus documentation says that averaging precomputed quantiles "yields statistically nonsensical values" and that a summary cannot be used when observations from several instances must be aggregated. The fix is to record counts per latency bucket, which can be added together, and compute the percentile from the merged buckets. The SRE book gives the same advice: "collect request counts bucketed by latencies" rather than raw latencies, with boundaries spaced roughly exponentially, and notes that sampling a value once a minute can miss the short spikes that drive tail latency.

    Buckets have a price: in Prometheus classic histograms the error of a quantile "is limited by the width of the bucket the quantile is located in", so a p99 read from a 300 to 1,000 ms bucket is only known to lie in that range. Put bounds around your target.

    flowchart LR accTitle: Right and wrong ways to combine latency percentiles accDescr: Two servers each report a p99. Averaging the two p99 values gives a number that matches neither the traffic mix nor the real tail. Instead each server reports bucket counts, the counts are added, and the p99 is read from the merged buckets, with an error limited by bucket width. A["Server A: p99"] --> W["Average of p99 values"] B["Server B: p99"] --> W W --> X["Wrong: ignores traffic mix"] A2["Server A: bucket counts"] --> M["Add counts"] B2["Server B: bucket counts"] --> M M --> Y["Read p99 from merged buckets"]

    Figure 2. Combine counts, not percentiles. How to read this: the top path throws away how many requests each server handled. The bottom path keeps every count, so the merged answer is the true one up to the bucket width.

    Coordinated omission

    A load generator that waits for each reply before sending the next stops sending while the server stalls, so it records one slow request instead of the hundreds that would have waited. The HdrHistogram Javadoc describes recordValueWithExpectedInterval as compensating "for the loss of sampled values when a recorded value is larger than the expected interval" with synthetic lower values, and says to use it or the post-recording correction, never both. The cleaner fix is to time each request from when it was due, which a fixed arrival rate (an open loop) does naturally.

    sequenceDiagram accTitle: A closed-loop load generator hides a server stall accDescr: The generator sends a request every 10 milliseconds but waits for each reply. The server stalls for two seconds on one request. The generator records one slow sample and then sends the delayed requests back to back, each timed from its actual send, so about two hundred requests that should have been sent during the stall are never counted as slow. participant G as Load generator participant S as Server G->>S: request 3000 (due at 30.000 s) Note over S: stalls 2 s S-->>G: reply after 2 s Note over G: records one slow sample G->>S: requests 3001, 3002... sent late, back to back S-->>G: fast replies, timed from the late send Note over G: the ~200 requests due during the stall look fast

    Figure 3. The stall the report never sees. How to read this: the slow request is counted once, and the requests that were delayed behind it are timed from when they were finally sent, so they look healthy.

    Measuring the wrong thing

    Measure at the caller as well as the callee: a server-side timer usually starts after a request is accepted, so it can exclude the queue in front of it. State the percentile, window and rate in every requirement ("p99 under 300 ms over five minutes at 2,300 requests per second").

    Tail-tolerant techniques

    Hedged requests. Send the request to one replica; if it has not answered after a short delay, send a copy to another and use the first answer, cancelling the rest. Naive versions "typically add unacceptable additional load", so the usual variant waits until the call is older than the 95th-percentile latency, which "limits the additional load to approximately 5%". In the paper's benchmark reading 1,000 keys from a table over 100 servers, a hedge after 10 ms cut the 99.9th-percentile latency from 1,800 ms to 74 ms for about 2 percent more requests. gRPC shows the production form: a hedgingDelay, a maxAttempts capped at 5, and a token throttle that cancels hedges when failures drain the bucket. Hedging works because slowness is often "due to other forms of interference" rather than inherent in the request, and only while the cause does not hit several replicas at once.

    Tied requests. Enqueue the request on two servers, each tagged with the other; when one starts it cancels its twin. With a 1 ms stagger the paper reports a nearly 40 percent cut at the 99.9th percentile for file-system reads, at under 1 percent extra disk utilization.

    Deadlines and good-enough responses. Give each call a deadline and, when an optional dependency misses it, answer without it. The paper returns "good enough" search results once an acceptable fraction of servers has answered, and skips ads or spelling correction that do not respond in time. See graceful degradation.

    Smaller queues, smaller units. Keep low-level queues short so priority policies take effect, split heavy background work, and use "micro-partitions": many more partitions than machines, so load can be shed "in roughly 5% increments" (the paper's example has about 20 per machine). Probation sidelines a machine that is slow right now while probing it, and canary requests try a risky request on one or two servers first.

    Limit the blast radius. A circuit breaker and bulkhead stop one slow dependency from filling every thread, and load shedding keeps queues short when load exceeds capacity.

    flowchart TD accTitle: Choosing a tail mitigation accDescr: A decision flow. If the slow part is optional, use a deadline and a fallback. If the call is a safe read with independent slowness, hedge after the p95 with a throttle. If the cause is queueing under load, shed load and size for headroom. If the cause is a hot or skewed partition, rebalance or split it. S["p99 too high"] --> Q1{"Is the slow part optional?"} Q1 -->|yes| R1["Deadline and fallback"] Q1 -->|no| Q2{"Safe read, slowness
    is per server?"} Q2 -->|yes| R2["Hedge after p95, with a throttle"] Q2 -->|no| Q3{"Slow because queues
    build under load?"} Q3 -->|yes| R3["Shed load, add headroom"] Q3 -->|no| R4["Look for a hot partition
    or a shared resource"]

    Figure 4. A first-pass mitigation choice. How to read this: start from the cause, not the technique. Hedging a request whose slowness belongs to the request, such as a huge payload, adds load and changes nothing.

    Technique Gain Cost Wrong when
    Hedged requests Much shorter tail for independent slowness About 5 percent more calls at a p95 delay The call is not safe to repeat, or the dependency is overloaded
    Deadline plus fallback Bounded latency Weaker answers The answer is not optional
    Headroom Shorter queues A larger bill Cost is the constraint

    Build it: a seeded model of tail effects in Java

    This lab is a pure model: seeded random numbers and invented latencies, no real clock and no network. It measures nothing about a real system. It shows the shapes the sections above describe.

    Goal. See the mean hide a tail, a fan-out multiply it, a hedge cut it (and fail to), a closed-loop load generator hide a stall, and percentile averaging go wrong.

    Setup. From examples/backend:

    ./gradlew :labs:tail-latency-model:test
    ./gradlew -q :labs:tail-latency-model:run

    The first command runs 18 tests; the code is in examples/backend/labs/tail-latency-model/src/main/java/buildingai/labs/taillatency/. One call takes 10 to 20 ms 98 percent of the time and 200 to 400 ms otherwise; a seeded SplitMix64 generator makes every number repeatable.

    Part 1: the mean looks fine.

    Expected output, captured from a real run (Java 25.0.3, part 1 of the demo):

    Part 1. One call, 100000 samples: the mean looks fine, the tail does not.
      mean 20.8 ms | p50 15.1 | p90 19.2 | p95 19.7 | p99 304.0 | p99.9 389.4 | max 399.8
      share of calls above 100 ms: 2.0%

    The mean is 20.8 ms and p95 is 19.7 ms, yet p99 is 304 ms.

    Part 2: fan-out.

    Expected output, captured from a real run (part 2 of the demo):

    Part 2. One request waits for n parallel calls (20000 requests per row): a rare slow call becomes a common slow request.
      n    requests above 100 ms   formula 1-0.98^n   p50 ms   p99 ms   p99.9 ms
      1    1.9%                    2.0%               15.1     288.1    386.6
      10   17.5%                   18.3%              19.5     389.9    399.1
      50   63.7%                   63.6%              263.3    398.2    399.9
      100  86.6%                   86.7%              330.1    399.0    399.9

    The measured share tracks the formula. At 100 calls the median request is a slow one (330 ms).

    Part 3: hedging.

    Expected output, captured from a real run (part 3 of the demo):

    Part 3. Hedged calls: send a second copy of a call that has not answered after the single-call p95 (19.7 ms), take the first answer.
      case                                        n    p50 ms   p99 ms   p99.9 ms   above 100 ms   extra calls
      no hedge                                    1    15.1     299.0    388.7      1.9%           0.0%
      hedge, slowness is per server (independent) 1    15.1     34.7     39.5       0.0%           4.9%
      hedge, slowness sticks to the request       1    15.1     263.1    363.4      1.9%           4.9%
      no hedge                                    100  329.9    398.9    399.9      86.6%          0.0%
      hedge, slowness is per server (independent) 100  36.4     308.3    375.0      3.9%           4.9%
      hedge, slowness sticks to the request       100  291.7    392.9    398.7      86.6%          4.9%

    For one call, a hedge after the p95 cuts p99 from 299 ms to 34.7 ms for 4.9 percent extra calls, close to the paper's "approximately 5%". When slowness sticks to the request, the same load buys almost nothing (the small p99 drop is the copy being a fresh draw inside the slow range). With a 100-way fan-out, hedging fixes the median (329.9 to 36.4 ms) but not the p99: 3.9 percent of requests still have a call that was slow twice, more than 1 percent.

    Part 4: coordinated omission.

    Expected output, captured from a real run (part 4 of the demo):

    Part 4. A load generator sends one request every 10 ms but waits for each reply (6000 requests, a 2000 ms server stall at 30 s).
      timed from                          p50 ms   p99 ms   p99.9 ms   max ms   requests above 100 ms
      the moment it was sent (naive)      6.0      7.0      7.0        2005.2   1
      the moment it should have been sent 6.1      1769.5   1981.0     2005.2   474

    The naive report says p99 is 7.0 ms and one request was slow. Timed from when each was due, 474 requests waited over 100 ms and p99 is 1,769.5 ms.

    Part 5: merging percentiles.

    Expected output, captured from a real run (part 5 of the demo):

    Part 5. Two servers behind one load balancer: A takes 97000 requests and is never slow; B takes 3000 requests and is always slow.
      p99 of server A 19.9 ms | p99 of server B 398.0 ms | average of the two p99 values 208.9 ms
      p99 of all 100000 requests together: 331.0 ms
      merged bucket counts (ms): <=10: 8, <=30: 96992, <=100: 0, <=300: 1505, <=1000: 1495, above: 0
      p99 read from the merged buckets: above 300.0 ms and at most 1000.0 ms

    The average of the two p99 values is 208.9 ms; the true p99 is 331.0 ms. The merged buckets give the right range (300 to 1,000 ms) and no better.

    Break it. In Fanout.run, make the copy always fast (boolean slow2 = false;). Two tests fail (checked: 2 of 18), because the sticky case now looks as good as the independent one. Restore the line.

    In practice: ShopStream's product page before a promotion

    This is the realistic example, an educational scenario on the course's running example ShopStream; nothing in it describes a real company. Every number is illustrative.

    This is a realistic scenario, not a case history.

    The situation

    The product page makes five parallel calls and has a p99 target of 400 ms. Dashboards show each backend's p99 is within target and the page's p99 is not. A promotion that doubles page views starts in two weeks.

    Starting architecture

    The page service is the one in Figure 1. It waits for all five calls with a 2-second per-call timeout and reports a mean latency per instance once a minute.

    Options considered

    Option Effect Risk
    A. Hedge every call after its p95 Shortens independent slowness About 5 percent more load, worse if a backend is overloaded
    B. Make recommendations and reviews optional with a 150 ms deadline Bounds the page by the required calls Pages sometimes appear without them
    C. Fix the slowest backend Removes one cause Does not change the fan-out arithmetic

    The decision

    B first, because two of five calls are optional and a deadline costs no extra load. Then A for the idempotent catalogue read only, with a token throttle. The metric changes first: per-request latency is recorded in histogram buckets with bounds around 400 ms, and the percentile is computed from merged counts.

    Rollout and verification

    Release B to a small share of traffic and compare the page p99 from merged buckets with a control. Alert on the share of pages that lose a component. Load-test at a fixed rate, timing from the intended send moment, so a stall is not hidden.

    The 2 a.m. failure

    The page reads: page p99 and error rate both rise, and hedge volume has tripled. The stock service is overloaded; the page's hedges and retries add load to it, which makes it slower, which triggers more hedges. First checks: hedged calls as a share of all calls, the stock service's queue depth, and the throttle's token level. Mitigation: disable hedging on that call and shed load at the stock service. The lasting fix is a hedge throttle that stops hedging when the error or timeout rate rises, which is what the gRPC token mechanism is for, and an alert on hedge share. A hedge is a bet that slowness is independent; an overloaded dependency makes the bet lose for every caller at once.

    Architect's notes

    • Write the SLO as a percentile, a window and a rate. Without all three, nobody can tell whether a measurement meets it.
    • Count calls per request. A page with 100 calls needs each call's p99.99 healthy for its own p99 to be.
    • Prefer deadlines to bigger timeouts. One deadline carried to every call bounds the whole request.
    • Hedge only safe, repeatable reads, and tie the hedge to a throttle.
    • Keep bucket bounds near the target. A 300 to 1,000 ms bucket cannot tell a 310 from a 900.

    Common mistakes

    • Reporting the mean or one p99 per server. Neither is a fleet percentile.
    • Averaging percentiles over time or across servers. Merge bucket counts.
    • A closed-loop load test with no correction. It reports the stall as one slow request.
    • Hedging without a throttle or on unsafe requests. Hedged writes can run twice, and hedges multiply load in an incident.
    • Treating fan-out as free. Ten calls at 1 percent slow each makes about one page in ten slow.

    Key takeaways

    • A percentile is a position in sorted timings; the p99 is the one request in a hundred.
    • A fan-out of n calls is slow with probability 1 - (1 - q)^n: rare per call, common per request.
    • Merge bucket counts, never percentiles, and time requests from when they were due.
    • Hedge only independent, repeatable slowness, after about the p95, with a throttle.
    • Deadlines and good-enough answers bound the tail without extra load.

    Practice exercises

    1. Fan-out arithmetic (10 minutes). A page calls 8 services, each slower than its own p99 on 1 percent of calls. How often is the page slow, and how many calls push it past 10 percent?
    2. Read a hedge (15 minutes). In Part 3, why does the 100-way fan-out with a p95 hedge still have a slow p99? What would you try next, and what would it cost?
    3. Choose bucket bounds (15 minutes). Your SLO is p99 under 250 ms. Propose six bucket bounds and say what error a p99 read from them can have.

    The other side of this topic

    The front-end track measures the same tail from the visitor's side, where it includes the network and the device. See real-user monitoring.

    Official documentation

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments