Percentiles of Live Data Capture
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Percentiles are one of the most useful ways to summarize live data. In monitoring systems, they tell you much more than a simple average because they show how the distribution behaves, especially near the slow or extreme tail.
That is why teams talk about p50, p95, and p99 for live latency, queue time, or request duration. Those values answer practical questions such as "what is normal" and "how bad are the slowest few percent of events."
What a Percentile Means in a Stream
If your latency is 120 ms at the 95th percentile, that means 95% of observed requests were at or below 120 ms, and the slowest 5% were above it.
In live systems:
- '
p50is the median and often represents a typical request' - '
p95shows tail latency seen by slower users' - '
p99highlights rare but important slowdowns'
This matters because averages can hide bad user experience. A service with many fast requests and a small number of very slow ones may still have a decent average while feeling unreliable to real users.
Exact Percentiles on a Sliding Window
For a bounded recent window, exact percentiles are easy to compute. The usual pattern is to keep the last N values, sort them when needed, and pick the percentile position.
This works well for a recent rolling window such as the last 1000 requests. It is exact, simple, and good for small or moderate volumes.
The limitation is memory and sorting cost. If your stream is effectively unbounded, storing every event forever is not realistic.
Approximate Percentiles for True Live Streams
For high-volume live capture, teams usually switch to approximate percentile algorithms. Common approaches include histograms, t-digests, and other streaming summaries.
The idea is not to store every raw event. Instead, maintain a compact data structure that can answer percentile queries with acceptable error.
A simple bucketed histogram illustrates the concept:
This histogram is only approximate, but it is fast and memory-stable, which is often the right tradeoff for telemetry pipelines.
Choose a Window Before You Trust the Number
One subtle but important point: percentile values only make sense relative to a defined time window or sample window.
For example:
- '
p95 over the last 5 minutes' - '
p99 over the last 10,000 requests' - '
p50 for each one-minute bucket'
Without a window definition, percentile numbers can be misleading. A lifetime p95 may hide a current outage, while a tiny sample window may be too noisy to trust.
Common Pitfalls
- Using the average when tail behavior is what actually matters.
- Reporting percentiles without stating the time or sample window.
- Averaging percentiles from different windows. Percentiles do not combine that way.
- Calculating
p99on very small sample sizes, where the number becomes unstable. - Mixing units such as milliseconds and seconds in the same stream.
Summary
- Percentiles describe distribution better than averages, especially for live latency data.
- '
p50,p95, andp99are common because they capture both typical and tail behavior.' - Exact percentiles are practical for bounded sliding windows.
- Long-running high-volume streams usually need approximate algorithms such as histograms or t-digests.
- Always define the time window or sample window, or the percentile is hard to interpret correctly.

