Your web server just handled its ten-millionth request. You want to know the median response time and the 99th percentile â the p99, the number that reveals whether the slowest one percent of your users are suffering. The naive approach: save every measurement, sort them, and read off the right positions. That works fine for a thousand requests. For a billion it means gigabytes of storage, minutes of sorting, and a result that is already stale by the time you have it.
What you really need is a streaming algorithm: something that processes each value once and keeps only a tiny summary â a sketch â from which you can read off any percentile at any moment.
The t-digest, invented by Ted Dunning and Otmar Ertl and published in 2019, is one of the most elegant solutions to this problem. It stores not raw values but a small list of weighted centroids â (mean, count) pairs that summarize clusters of nearby values. Its key insight is that the sketch needs to be most accurate at the extremes: an estimate of the median can afford a little slack, but an estimate of the p99.9 must be tight, because that is where rare, painful outliers live.
To enforce that guarantee, the t-digest uses a scaling function that limits how many data points any single centroid near the tails may absorb. Centroids near the median can grow large and coarse; centroids at the very edges stay small and precise.
Comments
Loading comments...