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 () independently on of calls. What fraction of requests is slow, how would you split a 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 independent shards and each shard is slow with probability , all finish fast with probability , so the overall slow fraction is . A small shard tail grows into slow user requests at , which must be controlled through tight per-stage budgets, hedged requests and partial timeouts.
Steps
- Define p50 and p99: p50 (the 50th percentile, or median) is the latency at or below which of requests complete, reflecting typical speed. p99 (the 99th percentile) is the latency at or below which of requests complete, measuring the slow tail that active users frequently experience.
- Probability all 50 shards are fast: each shard finishes within with probability . Assuming independence across the parallel shards, all finish within with probability .
- Fraction of slow requests: the request is slow if at least one shard exceeds , which occurs with probability , or of all requests.
- Budget a end-to-end p99 target across stages (example allocation): for network and API (application programming interface) gateway overhead, for online feature lookup, for candidate retrieval, for ranking model inference, and for post-ranking business rules and safety margin.
- 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 budget.
- 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
- Tracking only average or p50 latency; a fast median can hide a p99 that degrades user sessions.
- Assuming a shard tail stays after parallel fan-out, forgetting the compounding.
- Retrying every slow shard immediately without a hedging delay or retry budget, which amplifies load during congestion.
How long your answer should be
Define p50/p99, work the calculation, sketch the split and name three mitigations; about 3 minutes.
Read this
Previous in ML system design: Mixed-precision Adam requires bytes per parameter ( B fp16 weights, B fp16 gradients, B fp32 master weights, and B each for Adam moments and ). For a -billion-parameter model across 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?