What do p50 and p99 latency mean? Suppose a request fans out to 50 shards in parallel and waits for all of them, and each shard is slow (>100 ms) independently on 1% of calls. What fraction of requests is slow, how would you split a 200 ms p99 latency budget across ML serving stages, and how can you reduce tail latency?

ML system design, Estimation
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you understand latency percentiles, why parallel fan-out across shards (partitions of an index or database) magnifies rare slow calls, and how real serving systems budget and mitigate tail latency.

Key idea

If a request waits for n independent shards and each shard is slow with probability p, all n finish fast with probability (1−p)n, so the overall slow fraction is 1−(1−p)n. A small 1% shard tail grows into 39.5% slow user requests at n=50, which must be controlled through tight per-stage budgets, hedged requests and partial timeouts.

Steps

  1. Define p50 and p99: p50 (the 50th percentile, or median) is the latency at or below which 50% of requests complete, reflecting typical speed. p99 (the 99th percentile) is the latency at or below which 99% of requests complete, measuring the slow tail that active users frequently experience.
  2. Probability all 50 shards are fast: each shard finishes within 100 ms with probability 1−0.01=0.99. Assuming independence across the 50 parallel shards, all 50 finish within 100 ms with probability 0.9950≈0.6050.
  3. Fraction of slow requests: the request is slow if at least one shard exceeds 100 ms, which occurs with probability 1−0.9950≈1−0.6050=0.3950, or 39.5% of all requests.
  4. Budget a 200 ms end-to-end p99 target across stages (example allocation): 20 ms for network and API (application programming interface) gateway overhead, 20 ms for online feature lookup, 40 ms for candidate retrieval, 90 ms for ranking model inference, and 30 ms for post-ranking business rules and safety margin.
  5. Note how stage budgets combine: stage p99 values do not simply add linearly unless all stages hit their tail on the same request, yet keeping each stage strictly bounded stops one slow component from exhausting the 200 ms budget.
  6. Apply tail-latency mitigations: send hedged requests (re-issue a call to a second replica if the first has not replied after a short delay such as the p95 latency, and use whichever finishes first), set strict shard timeouts that return partial results rather than blocking on the slowest shard, and reduce shard fan-out where possible.

Common mistakes

How long your answer should be

Define p50/p99, work the 1−0.9950 calculation, sketch the 200 ms split and name three mitigations; about 3 minutes.

Read this

Previous in ML system design: Mixed-precision Adam requires 16 bytes per parameter (2 B fp16 weights, 2 B fp16 gradients, 4 B fp32 master weights, and 4 B each for Adam moments m and v). For a 7-billion-parameter model across N=8 GPUs, how much per-GPU memory do model states take under plain data parallelism and ZeRO stages 1, 2 and 3?
Next in ML system design: Why must training features be joined “as of” each label’s timestamp, and how does a point-in-time join work? Using a small user timeline, why do naive joins inflate offline metrics and then fail online, and what is one serving-time alternative?