What is taught wrongly

The digest that promises nothing

The t-digest is the quantile structure most widely deployed and the only one with no proven bound on its rank error at any quantile. Measured, it beats the structure that does have one — and on two clusters with a gap between them it returns 431.5, where the data holds nothing at all between 40 and 800.

Every structure in this collection has been given a claim and a test its claim could fail. The t-digest has no claim.

That is not a criticism and it is not an omission by its author. Ted Dunning’s papers are explicit about it: the argument for the structure is that its centroid sizes are bounded by a stated scale function, and that this is observed to produce small relative error at the tails. There is no theorem. There is a rule about sizes and a body of empirical evidence, and the structure is, by a wide margin, the most deployed quantile summary there is.

So the only thing to do with it here is measure it.

One query — the 0.52 quantile — answered by 3 summariesThe true 0.52 quantile of 40,000 bimodal values is 802, marked by the line. Each bar is what a summary answered. Greenwald–Khanna says 802 — a rank error of 0.398% of the stream, which is 0.8% of the tail, and a value error of 0.0%; high-biased says 802 — a rank error of 0.392% of the stream, which is 0.8% of the tail, and a value error of 0.0%; t-digest says 675 — a rank error of 2.092% of the stream, which is 4.4% of the tail, and a value error of 15.7%. Every one of these is inside whatever it promised, where it promised anything. The numbers a reader would act on differ by more than an order of magnitude.Greenwald–Khanna7,008 bits802high-biased55,008 bits802t-digest6,144 bits675the truth, 802ε = 0.01, δ = 100 · 40,000 valuesq = 0.52
Fig. 1 The 52nd percentile of a stream made of two clusters — one around 20, one around 820, nothing in between. Two summaries return a number from the upper cluster, which is where the answer is. The third returns 675, and no value between 40 and 800 ever arrived.

The scale function is the whole structure

A t-digest holds centroids: pairs of a mean and a count. A new batch of values is sorted and merged into the existing centroids left to right, and a centroid is allowed to keep absorbing while its span in a transformed coordinate stays under one:

k(q)=δ2πarcsin(2q1)k(q) = \frac{\delta}{2\pi} \arcsin(2q - 1)

The arcsine is the mechanism and it is worth understanding directly. Its derivative is δ2πq(1q)\frac{\delta}{2\pi\sqrt{q(1-q)}} — small near q=12q = \tfrac12, unbounded at either end. So a centroid in the middle may absorb a wide stretch of the distribution before its kk-span reaches one, and a centroid at q=0.999q = 0.999 may absorb almost nothing.

That is where the tail accuracy comes from, and it comes without anybody stating an ε\varepsilon. There is one parameter, δ\delta, and it sets the total number of centroids to roughly δ\delta — sixty-two at δ=100\delta = 100 in the measurements here, which at a mean and a count each is 5,952 bits.

Where each summary keeps its stored valuesEvery stored value in each summary, placed at the quantile it sits at in the data — 40,000 draws from a Pareto distribution. Greenwald–Khanna keeps 74 of them in 7,104 bits; high-biased keeps 580 of them in 55,680 bits; t-digest keeps 62 of them in 5,952 bits. Greenwald–Khanna spreads them evenly, because its invariant caps every tuple's uncertainty at the same fraction of the stream wherever it sits. The biased summary crowds them into the top, because its cap there is a fraction of a tail that is itself small — and that crowding is exactly what the extra bits bought. The digest's spacing comes from an arcsine, which is dense at both ends and sparse in the middle, and it is a rule about shape rather than a promise about error.Greenwald–Khanna74 kept · 7,104 bitshigh-biased580 kept · 55,680 bitst-digest62 kept · 5,952 bits00.50.91quantile of the dataε = 0.01, δ = 100 · 40,000 values74 / 580 / 62 stored values
Fig. 2 Where the three summaries put their stored values. Greenwald–Khanna is even, because its cap is even. The biased summary crowds the top, because its cap goes to nothing there. The digest is dense at both ends and sparse in the middle, which is the arcsine drawn.

Measured, it is good

Rank error as a fraction of the tail it is about, averaged over eight independent streams of forty thousand heavy-tailed values:

quantile Greenwald–Khanna t-digest high-biased
0.5 0.64% 0.33% 0.46%
0.9 3.63% 1.15% 0.44%
0.99 47.28% 10.91% 0.56%
0.999 100.00% 55.62% 0.00%
bits 7,080 5,952 56,064

It is better than the structure with the proven bound, at fewer bits, at every quantile. And it is far worse than the structure whose bound is stated relative to the tail, at a ninth of that structure’s state.

That is the honest ranking and it does not fit a story in which guarantees are what matter. A guarantee is a floor under the behaviour, not a description of it, and Greenwald–Khanna’s floor is low enough at a tail percentile that a structure with no floor at all can walk under it.

Rank error at q = 0.999, as a fraction of the tail, against bitsEach point is one summary at one setting, averaged over 8 independent value streams of 40,000 draws — averaged because a far-tail rank error is a measurement over a handful of items and wanders by tens of per cent from one stream to the next. The vertical axis is the rank error divided by the mass the quantile is about, which is the number a reader of the 0.999 percentile cares about; measured against the whole stream instead, every one of these summaries looks accurate. Greenwald–Khanna runs from 100.0% at 1,500 bits to 100.0% at 14,208; t-digest runs from 49.1% at 2,976 bits to 2.5% at 49,140. Both axes are logarithmic.10,0000.11bits of state heldrank error ÷ tail mass at q = 0.999Greenwald–Khannat-digest8 streams per point · truth held apartq = 0.999, tail mass 0.001
Fig. 3 The far tail against state, for the two cheap structures. One of them improves with state and one of them does not — the uniform cap is flat at a hundred per cent of the tail across a tenfold increase in bits, and the digest’s error falls by a factor of twenty over the same range.

What it has instead of a promise, and where that runs out

The scale function does imply something, and it is worth deriving because what it implies is not what the structure is usually described as delivering.

Setting Δk=1\Delta k = 1 gives Δq=2πq(1q)/δ\Delta q = 2\pi\sqrt{q(1-q)}/\delta, so the rank error at quantile qq is proportional to q(1q)\sqrt{q(1-q)}. Divide by the tail mass 1q1-q to get the error relative to the question and it is proportional to

q(1q)1q=q1q\frac{\sqrt{q(1-q)}}{1-q} = \sqrt{\frac{q}{1-q}}

which grows without bound as q1q \to 1. The accuracy improves towards the tail and the accuracy relative to the tail gets worse, and both statements are true of the same numbers. The structure is relative-ish, and it is not relative.

Measured against that prediction, over twenty streams:

quantile measured, δ=100\delta = 100 the scale predicts measured, δ=400\delta = 400 predicts
0.9 1.2% 19% 0.1% 5%
0.99 11.0% 63% 0.8% 16%
0.999 61.5% 199% 7.1% 50%
0.9999 65.0% 628% 28.8% 157%

Two things. The structure is between three and sixteen times better than its own scale function’s bound, because a query interpolates between adjacent centroid means rather than returning one, and interpolation recovers most of a centroid’s width. That is a real advantage of the query rule and it is not in the sizing argument at all.

And the growth is there. From q=0.9q = 0.9 to q=0.999q = 0.999 the tail-relative error rises by a factor of fifty at δ=100\delta = 100 and seventy at δ=400\delta = 400. The direction matches the derivation; the magnitude is steeper than q/(1q)\sqrt{q/(1-q)}, which predicts about ten. So the shape is right and the constant is not, and this collection can state the ordering — the far tail is relatively worse than the near tail, at every δ\delta — without claiming the exponent.

Which is the sentence “the t-digest gives relative error at the tails” gets wrong. It gives decreasing absolute error at the tails. Relative to what is being asked about, it gives increasing error, and the structure that gives genuinely flat relative error is the one from the previous essay, at nine times the state.

Rank error as a fraction of the tail it is aboutThe same measurements as a plate reporting error against the stream, divided by the mass the quantile is about — 1 − q, which is a half at the median and a thousandth at q = 0.999. Averaged over 8 independent streams of 40,000 Pareto values. A relative promise is a flat line on this plate and an absolute one climbs, because the numerator is constant and the denominator is shrinking. t-digest: 1.15% → 11% → 56% → 47%; high-biased: 0.44% → 0.56% → 0.00% → 0.00%. The vertical axis is logarithmic.0.1%1%10%0.90.990.9990.9999quantile asked forrank error ÷ (1 − q)t-digest5,952 bitshigh-biased56,064 bits8 streams per point · ε = 0.01, δ = 100denominator: the tail
Fig. 4 The two structures at the tail end only, where the difference is a slope. One line is flat by construction and one climbs, and the climbing one is the structure usually described as the relative-error option.
Rank error as a fraction of the tail it is aboutThe same measurements as a plate reporting error against the stream, divided by the mass the quantile is about — 1 − q, which is a half at the median and a thousandth at q = 0.999. Averaged over 8 independent streams of 40,000 Pareto values. A relative promise is a flat line on this plate and an absolute one climbs, because the numerator is constant and the denominator is shrinking. Greenwald–Khanna: 0.64% → 1.37% → 3.63% → 47% → 100%; high-biased: 0.46% → 0.42% → 0.44% → 0.56% → 0.00%; t-digest: 0.33% → 0.50% → 1.15% → 11% → 56%; low-biased: 0.42% → 0.95% → 3.60% → 40% → 100%. The vertical axis is logarithmic.0.1%1%10%100%0.50.750.90.990.999quantile asked forrank error ÷ (1 − q)Greenwald–Khanna7,080 bitshigh-biased56,064 bitst-digest5,952 bitslow-biased56,688 bits8 streams per point · ε = 0.01, δ = 100denominator: the tail
Fig. 5 All four caps on one plate, tail-relative. The two biased rules are flat where their cap is small and climb where it is not; the uniform rule climbs everywhere; the digest sits between them, which is where its reputation comes from and is not the flat line the reputation describes.

It is not comparison-based, and that has consequences

Here is the property that separates the digest from every other quantile summary in this collection, and it is not obvious from the description.

Greenwald–Khanna and the biased summary touch the data with <= and nothing else. As the previous essay establishes, their rank errors are therefore identical under any strictly increasing relabelling of the values — the same permutation of ranks produces the same structure and the same answers by rank.

A t-digest takes means. That is not a comparison. Relabel the values monotonically and the centroid means land somewhere else, the merge decisions change, and the rank errors move:

q=0.5q = 0.5 q=0.9q = 0.9 q=0.99q = 0.99 q=0.999q = 0.999
Greenwald–Khanna, original values 0.00300 0.00265 0.00685 0.00100
Greenwald–Khanna, exponentiated 0.00300 0.00265 0.00685 0.00100
t-digest, original values 0.00065 0.00015 0.00005 0.00065
t-digest, exponentiated 0.00520 0.00060 0.00000 0.00060

The digest’s rank error at the median went up eightfold under a relabelling that no comparison-based structure can even detect. Both halves of that are asserted on every build, because a check that only demanded the first pair match would be satisfied by a structure that had stopped working.

The consequence is not that the digest is worse. It is that the digest’s accuracy is a property of the data as well as of the parameter, so a measurement of it on one distribution is evidence about that distribution and not a bound. Every number in this essay is a measurement on stated streams, and there is no argument available here that would extend any of them to a stream nobody has tried. For the comparison-based structures there is.

The answer that never occurred

The sharpest consequence of taking means is on the plate at the top of this page.

Build a stream of two clusters — half the values uniform on [0,40][0, 40], half uniform on [800,840][800, 840], nothing in between — and ask for quantiles near the middle.

quantile truth Greenwald–Khanna high-biased t-digest
0.45 36.1 36.0 35.8 36.0
0.48 38.4 38.0 38.5 38.3
0.50 800.1 800.4 39.7 431.5
0.52 801.7 802.0 802.0 675.4
0.55 804.0 803.4 804.2 804.4

Two of the three summaries are wrong at q=0.5q = 0.5, and they are wrong in different ways. The biased summary returns 39.7 — the wrong side of the gap, but a value that arrived. Its high-biased cap at the median permits a rank error of εn/2\varepsilon n / 2, which is two hundred items, and two hundred items at the median of this distribution is the whole crossing. That is a correct structure meeting its promise on a distribution where the promise is not enough, which is the previous essay’s subject with the ends swapped.

The digest returns 431.5, and no value between 40 and 800 ever arrived. It is not on the wrong side of the gap; it is in the gap.

The mechanism is the query rule rather than the sizing. Not one centroid has a mean inside the empty region — the merge never crosses it, because the sorted batch has no values there — but a query interpolates between the mean of the last low centroid and the mean of the first high one, and the straight line between them passes straight through the void.

Every value a comparison-based summary returns is a value that arrived. That is not stated as a property of those structures anywhere, because it is too obvious to say: they store observations and return one. A structure that stores averages does not have it, and the interpolation that made it three to sixteen times better than its own bound at the tail is what takes it away.

One query — the 0.5 quantile — answered by 3 summariesThe true 0.5 quantile of 40,000 bimodal values is 800, marked by the line. Each bar is what a summary answered. Greenwald–Khanna says 800 — a rank error of 0.440% of the stream, which is 0.9% of the tail, and a value error of 0.0%; high-biased says 39.7 — a rank error of 0.400% of the stream, which is 0.8% of the tail, and a value error of 95.0%; t-digest says 432 — a rank error of 0.092% of the stream, which is 0.2% of the tail, and a value error of 46.1%. Every one of these is inside whatever it promised, where it promised anything. The numbers a reader would act on differ by more than an order of magnitude.Greenwald–Khanna7,008 bits800high-biased55,008 bits39.7t-digest6,144 bits432the truth, 800ε = 0.01, δ = 100 · 40,000 valuesq = 0.5
Fig. 6 The median of the same two clusters. The truth is in the upper one. One summary lands there, one lands in the lower cluster, and one lands between them where there is nothing.
Rank error as a fraction of the tail it is aboutThe same measurements as a plate reporting error against the stream, divided by the mass the quantile is about — 1 − q, which is a half at the median and a thousandth at q = 0.999. Averaged over 8 independent streams of 40,000 bimodal values. A relative promise is a flat line on this plate and an absolute one climbs, because the numerator is constant and the denominator is shrinking. Greenwald–Khanna: 0.88% → 1.31% → 4.94% → 39% → 100%; high-biased: 0.39% → 0.48% → 0.48% → 0.44% → 0.00%; t-digest: 0.55% → 0.11% → 0.63% → 4.72% → 34%. The vertical axis is logarithmic.0.1%1%10%100%0.50.750.90.990.999quantile asked forrank error ÷ (1 − q)Greenwald–Khanna7,152 bitshigh-biased56,352 bitst-digest6,024 bits8 streams per point · ε = 0.01, δ = 100denominator: the tail
Fig. 7 Rank errors on the same clustered stream, which look unremarkable — a rank error does not know about a gap, because a rank error does not know about values. The table above is a value story and this plate is why nothing in the usual measurement of these structures would show it.

Why it is deployed and the others are not

It is worth stating the practical case plainly, because an essay in this field that only listed a structure’s defects would be misleading about why it exists.

One parameter, and it is a size. δ\delta sets the centroid count directly, so a memory budget translates into a parameter without arithmetic. An ε\varepsilon does not: the tuple count of a Greenwald–Khanna summary at a given ε\varepsilon depends on the stream length and is discovered rather than chosen.

Bounded state, unconditionally. The digest holds about δ\delta centroids however long the stream runs. Both comparison-based summaries here grow logarithmically in nn, which is small and is not nothing when the alternative is a fixed array.

Cheap updates. Values go into a buffer and the structure is rebuilt once per buffer, so the per-arrival cost is an array append and the merge cost is amortised across hundreds of arrivals. Greenwald–Khanna does an insertion into a sorted list on every arrival and a compression pass every 1/2ε1/2\varepsilon of them.

And it is good where most questions are. At the 90th percentile it is a third of Greenwald–Khanna’s error at four-fifths of the bits, and a ninth of the state of the structure that beats it.

None of that is a guarantee, and all of it is what an engineer choosing a library actually weighs. The gap this essay is about is not that the structure is bad; it is that the sentence “relative error at the tails” is doing work in that decision that the structure does not support, and the two places where it fails — the far tail, and a gap in the data — are not where anybody looks.

What sorted input did not do

One thing worth reporting because it failed to reproduce.

A merging digest is often said to be vulnerable to input arriving in sorted order, on the grounds that each batch then merges into one end of the structure rather than across it. Measured, on the same heavy-tailed stream:

arrival order centroids error at 0.99 at 0.999
shuffled 62 13.5% 60.0%
sorted ascending 73 13.2% 72.5%
sorted descending 70 13.5% 60.0%

Nothing happens. The structure sorts each buffer before merging and rebuilds the centroid list from scratch on every flush, so an already-sorted buffer is not a special case for it. If there is an input that defeats this structure — and the literature on relative-error streaming quantiles gives reason to think adversarial ones exist — a plain sort is not it, and reporting the failed attempt is more useful than not having tried.

Rank error at q = 0.9, as a fraction of the tail, against bitsEach point is one summary at one setting, averaged over 8 independent value streams of 40,000 draws — averaged because a far-tail rank error is a measurement over a handful of items and wanders by tens of per cent from one stream to the next. The vertical axis is the rank error divided by the mass the quantile is about, which is the number a reader of the 0.9 percentile cares about; measured against the whole stream instead, every one of these summaries looks accurate. Greenwald–Khanna runs from 12.7% at 1,500 bits to 2.0% at 14,208; high-biased runs from 1.8% at 12,816 bits to 0.2% at 103,260; t-digest runs from 4.9% at 2,976 bits to 0.1% at 49,140. Both axes are logarithmic.10,000100,0000.0010.010.1bits of state heldrank error ÷ tail mass at q = 0.9Greenwald–Khannahigh-biasedt-digest8 streams per point · truth held apartq = 0.9, tail mass 0.1
Fig. 8 And the trade at the 90th percentile, where all three structures are competent and the digest is the cheapest of them by a factor of nine against the summary that beats it. Most quantile questions are here rather than in the far tail, and this is the plate that explains why the structure with no guarantee is the one that gets deployed.

What a claim without a test is worth here

This collection’s standing rule is that a claim gets a test it could fail, and an assertion that has never rejected anything proves nothing. The t-digest is the one structure here that arrives with nothing to test.

So what is asserted about it is what can be: not a bound, but a comparison that must come out in a stated direction. The digest’s tail-relative error at q=0.999q = 0.999 must exceed its own at q=0.9q = 0.9 by more than a factor of three, averaged over twelve independent streams, and the biased summary’s must not. That is a statement the plates rest on, it is measured rather than derived, and it fails if either the digest stops degrading or the biased summary starts.

And the structure is asked for its promise and must not have one. A query for promiseAt — the method every other summary in this family answers — is required to be absent, so that a plate drawing the digest cannot print a guarantee line beside its measurements. That is a small piece of machinery and it exists because the natural thing to do when drawing three structures on one plate is to give them all the same furniture.

A structure with no bound is not a structure with a bound of infinity. It is a structure whose behaviour has to be established by measurement on named inputs, every time, with no extension to inputs nobody has tried — which is exactly the position this collection is in with respect to it, and exactly what the sections above are.

A mean is not an observation

The gap failure is attributed above to the query rule, and interpolation is indeed what produced 431.5. The property that was lost is older than the query, and saying so makes the repair clearer.

A centroid holds a mean of several values, and a mean of a set need not belong to it. Even without any interpolation, a digest answering with a centroid’s mean is answering with a number that may never have arrived — three values of 10, 10 and 40 give a centroid at 20, and 20 is not in the data. On a continuous distribution nobody notices, because a number close to values that arrived is indistinguishable from one that did. On data with structure — integers, prices in whole pennies, latencies rounded to the millisecond, two clusters — it is exactly noticeable.

So the guarantee that comparison-based summaries have and this one lacks is not the answer is close; it is the answer is a member of the input. That is a stronger property than it sounds and it is worth naming because it decides whether a summary’s output can be used as a key, matched against a record, or presented as an example.

The repair, for anybody who needs it, is to change what a centroid stores. Keeping a representative — one of the values it absorbed, chosen and kept — rather than a mean restores the property outright, and the query then returns an observed value at the cost of the interpolation that made the structure three to sixteen times better than its own scale bound. That is a genuine trade rather than a free fix, and which side of it is right depends on whether the answer is going to be read as a number or used as a value.

And the two failures compose. A centroid mean is not an observation; an interpolation between two centroid means is not even close to one. The 431.5 in the table above is the second on top of the first, and only the second is usually discussed.

What has to be re-measured, and how cheaply

The consequence of having no bound is not that the structure might be wrong. It is that nothing about its accuracy transfers between deployments, and that is an ongoing cost rather than a one-off caveat.

Every number in this essay is a measurement on a named stream. The relabelling table shows why they cannot be extended: a monotone change of the values, which no comparison-based summary can even detect, moved the digest’s median rank error by a factor of eight. So a digest that was measured as accurate on last quarter’s latencies has been measured on last quarter’s latencies, and a change in the shape of the traffic — a new tier of customers, a caching layer, a unit change from milliseconds to microseconds — is a change to the thing that was measured.

That sounds like an argument against the structure and it is not, because the re-measurement is cheap and nobody does it.

Keep a uniform reservoir sample of a few thousand values alongside the digest. It costs a few tens of kilobytes, its own quantiles are exact on the sample, and the sample’s sampling error at a mid-quantile is well under a per cent at that size. Comparing the digest’s answers against the sample’s, periodically, gives a running measurement of the digest’s error on the traffic actually arriving — which is the number the structure cannot supply about itself and the number a bound would have supplied for free.

A structure with a guarantee needs no monitoring and a structure without one does, and the monitoring is a sampler that costs a fraction of the structure being monitored. That is the honest form of what “no guarantee” costs: not a risk to be accepted, but a small permanent overhead that the accuracy comparisons in this essay never charge to it.

What is not measured here

The scale functions that are not k1k_1. Implementations offer several — one that bounds the centroid count strictly, one that is uniform, one designed for merging — and each changes the shape of the error curve. Only the arcsine is measured here, and the numbers above are about it rather than about the structure’s name.

Merging digests. The structure’s main practical claim is that digests combine well, which is why it is in monitoring systems at all. Nothing here measures a merge.

Weighted and clustered inputs beyond these two. The clustered case above is one gap in one place. A distribution with many gaps, or with heavy discrete atoms, would put the interpolation under more strain and neither is measured. What can be said from what is here is that the failure needs a gap rather than a tail: on every continuous distribution tried, the digest’s answers were values close to values that arrived.

And the guarantee that does exist. Later work — Cormode, Karnin, Liberty, Thaler and Veselý, 2021 — gives a genuinely relative-error streaming quantile structure with a proven bound and a space cost close to the digest’s. It is a different structure, it is not built here, and quoting its numbers would be quoting.

Where each summary keeps its stored valuesEvery stored value in each summary, placed at the quantile it sits at in the data — 40,000 draws from a bimodal distribution. Greenwald–Khanna keeps 73 of them in 7,008 bits; high-biased keeps 573 of them in 55,008 bits; t-digest keeps 64 of them in 6,144 bits. Greenwald–Khanna spreads them evenly, because its invariant caps every tuple's uncertainty at the same fraction of the stream wherever it sits. The biased summary crowds them into the top, because its cap there is a fraction of a tail that is itself small — and that crowding is exactly what the extra bits bought. The digest's spacing comes from an arcsine, which is dense at both ends and sparse in the middle, and it is a rule about shape rather than a promise about error.Greenwald–Khanna73 kept · 7,008 bitshigh-biased573 kept · 55,008 bitst-digest64 kept · 6,144 bits00.50.91quantile of the dataε = 0.01, δ = 100 · 40,000 values73 / 573 / 64 stored values
Fig. 9 Where the three summaries put their stored values on the clustered stream. Every one of them puts almost nothing in the gap, which is correct — there is nothing there to store. What differs is what happens when a query falls between two stored things, and only one of these structures answers with something it did not observe.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

What links here

Every essay whose body links to this one.

The objects this essay names

Each one links to every other essay that touches it.

CounterexampleFalsificationGreenwald–KhannaGuaranteeHeavy tailInterpolationMeasurementQuantileRank errorSummaryT-digestTail