The guarantee that is one query wide
Accurate to within one per cent, with 99% confidence.
That sentence is four claims. Within one per cent of what. With 99% confidence of what event. Per query, or across all queries. And measured on which stream. Three of the four are usually dropped, and each of the three, dropped, turns the sentence into something that is not true of the structure it describes.
Within one per cent of what
The bound is . The multiplies , the length of the whole stream, and never .
That is not fine print. It is the difference between a structure that is uniformly accurate and one that is accurate about exactly the keys that carry most of the data. On the stream here — sixty thousand items, 3,528 distinct keys, Zipf-shaped — the additive slack at is counts. For the key that occurred 9,579 times that is a possible 27% and a measured 4%. For one of the 836 keys that occurred exactly once, the same 2,548 counts is a possible 254,700%.
A relative-error guarantee is a completely different object, and no structure of a fixed size can offer one. To be within 1% of a key that occurred once, the sketch would have to distinguish a count of one from a count of two for every key in the universe, which is the exact hash map and the linear-space floor that the floor under a summary computes. The additive form is not laziness in the analysis; it is the only form available.
With 99% confidence of what event
is the probability that one query exceeds the additive bound. It is not the probability that the sketch is correct, and it is not a property of the sketch at all — it is a property of a query against a sketch, and the events for different queries are not independent.
The practical form of the mistake is the one that shows up in monitoring systems. A design with answering two hundred distinct queries is expected to breach on about four of them, and a system that alerts on any breach will alert. Nothing has gone wrong. The bound said one in fifty and there were two hundred.
Correcting for it is elementary — take for queries, which costs extra rows and is cheap because rows are logarithmic — and it is elementary only once somebody has noticed that the correction is needed. The bound as usually quoted contains no hint that the number of queries is a parameter.
The bound is loose, and by how much is not in the bound
Here is the measurement that makes the previous section awkward, and it is worth putting the two side by side rather than choosing one.
| depth | the design permits | measured breach rate over 35,280 queries |
|---|---|---|
| 1 | 36.8% | 6.3% |
| 2 | 13.5% | 0.43% |
| 3 | 5.0% | 0.023% |
| 4 | 1.8% | 0 |
Every measured rate is well under what the design allows, and the ratio grows with depth: six times at , thirty-one at , two hundred and seventeen at , and at not a single breach in thirty-five thousand queries against a permitted seven hundred.
So the per-query bound is honest and pessimistic, and the two failures — reading as a per-sketch probability, and reading it as a description of how often the structure actually misses — pull in opposite directions and can cancel. A practitioner who read as “the sketch is fine” and ran two hundred queries would probably have been right on this stream, for reasons that have nothing to do with the reasoning that got there.
This is the same shape as the constant the notation drops. The constant the notation drops is about a class that is right and a factor of three that decides everything; this is about a probability that is right and a factor of two hundred that decides whether the alarm fires. In both cases the missing quantity is a property of the input and the implementation, so no amount of staring at the bound recovers it and a measurement does.
Measured on which stream
Every number above is Zipf with exponent 1.1 over four thousand keys, and it is printed on every plate for the reason and are printed on every external-memory plate: change it and the numbers change.
The dependence is strong. On a uniform stream there are no heavy hitters at all, so the flat absolute error is a large relative error for every key at once and the sketch’s accuracy figures collapse across the board. On a more skewed stream the top key carries a larger share, the additive slack is a smaller fraction of it, and the same sketch looks better. A published accuracy figure with no stream attached is not a measurement of the structure.
Three more sentences that are not true
“The sketch is 99% accurate.” Accuracy and confidence are different parameters bought at different rates — against — and collapsing them into one percentage loses which was being described. A structure could be 99% confident of an answer that is 400% wrong, and several designs in this field are.
“More data makes it more accurate.” It makes it less accurate, in the only sense the bound describes: the additive term is and grows. A sketch of fixed size over a growing stream degrades, and the thing that stays constant is the error as a share of the stream. This is the opposite of the intuition carried over from sampling, where more data is unambiguously better, and it is the single most reliable way to catch a sketch that has been reasoned about as though it were a sample.
“It is accurate to within .” The bound says at most with probability at least . The realised error on the stream at hand is a different number, usually much smaller, occasionally larger, and never reported by the bound. A structure is deployed on a realised error and specified on a bound, and the whole of this site’s method is the position that the two need separate measurements.
Narrowing the table sharpens both readings at once, and in opposite directions, which is the clearest statement of what the guarantee is denominated in.
The interval nobody quotes
There is a construction that repairs a good deal of this and it costs almost nothing, which makes its absence from the usual account worth noticing.
Count-Min never goes below the truth. Misra-Gries never goes above it. Running both, at half the state each, gives an interval that provably contains the true count — not with probability , but certainly, because both one-sidednesses are unconditional.
The width of that interval is the honest error bar, it is computed from the data rather than from the parameters, and it is different for every key. For the heaviest key in this stream it is a few hundred counts on nearly ten thousand; for a key that occurred once it runs from zero to two and a half thousand, which is the structure saying, correctly, that it knows nothing.
A single number with a footnote is what gets quoted instead. The reason is not mysterious — one number is easier to put in an interface than two — and the cost is that the interface cannot distinguish “about nine thousand five hundred” from “somewhere between nought and two thousand five hundred”, which are the two things the sketch actually said.
What a bound is for
None of this makes the bounds wrong or useless, and it would be a poor conclusion to draw. A bound does a job no measurement can do: it holds for streams nobody has run, including adversarial ones, and it is what lets a structure be sized before the data exists.
What a bound cannot do is tell anybody what a particular deployment will see, and the gap between the two is not a small correction. Two hundred and seventeen times, at , on an ordinary stream. That is the size of the thing the bound is silent about, and it is the reason both numbers belong on the page.
Why this belongs in this field rather than beside the structure
The field of essays about what is taught wrongly has a consistent shape: a statement that is true, repeated in a form that has lost the conditions under which it is true. “Bubble sort is linear on nearly sorted data” is not what the counts say. “Quicksort sorts in place” covers three behaviours differing by a factor of n. “Hash lookup is O(1)” is a statement about an average over a family of hash functions and is not a statement about a run.
The sketch guarantee is the same shape and is worse in one specific way: the conditions are not merely omitted, they are encoded in a symbol that looks like it means something else. Reading as “ relative accuracy” is not carelessness about a caveat, it is a misreading of a formula that is right there. And the misreading is stable — it produces a mental model in which the structure is uniformly accurate, which is consistent with all the demonstrations anybody runs, because the keys anybody demonstrates on are the heavy ones.
What to ask instead
The useful question is not how accurate a sketch is. It is: what fraction of the stream is the smallest thing worth being right about?
That has a direct answer. If the smallest interesting key carries a share of the stream, and the estimate should be within a relative of it, then must be at most and the width follows as . To be within 10% on keys carrying 1% of the stream takes columns — 43 kilobytes at four rows and 32-bit counters — and to be within 10% on keys carrying a tenth of a per cent takes ten times that.
Asked that way the trade is visible and the sizing is arithmetic. Asked as “how accurate is a Count-Min sketch”, it has no answer, and the answers people give are measurements of their own test data.
The same reframing works on the confidence half. Not “how confident should the sketch be” but: how many queries will be asked, and what happens when one of them is wrong? A hundred queries feeding a dashboard a human reads can tolerate a breach a week; a hundred queries feeding an automatic action cannot, and the correction is extra rows, which is three. Both numbers are cheap once somebody has asked for them and neither is recoverable from a structure that was sized by copying the parameters out of a paper.
Which keys get worse as the stream grows
“More data makes it less accurate” is true in the sense the bound describes and it is worth sharpening, because the sharpened version explains why sketches are nonetheless deployed on streams that run for years.
The additive slack is and it grows with the stream. Whether that matters to a particular key depends on how that key grows.
A key whose share of the stream is stable — a popular endpoint that is always about 2% of traffic — has , and the relative error is . The cancels. Such a key is answered exactly as well after a year as after an hour, and no amount of stream makes it worse.
A key whose absolute count is fixed — something that happened four times last Tuesday and never again — has a relative error of , which grows without limit as the stream runs.
So the degradation is real and it is entirely confined to the second kind of key. That is a much more useful statement than the unqualified one, and it has a direct operational reading: a sketch over a growing stream is a structure whose accuracy about proportions is permanent and whose accuracy about rare absolute counts decays. A monitoring system asking “what share of requests hit this endpoint” is in the first case and needs no rotation; one asking “how many times did this error occur” is in the second and needs the sketch reset on a schedule, with the period set by how small an absolute count still has to be resolved.
It also explains the shape of the hero figure without any appeal to the bound. The keys on the left of it are the fixed-absolute-count keys, whose relative error is enormous and would grow; the keys on the right are the share-stable ones, whose relative error is small and would stay.
And the union bound assumes the queries were chosen first
The correction is right when the queries are fixed in advance. A great many real query sets are not, and the way they are chosen is the worst possible one.
The commonest use of a frequency sketch is to find the heavy keys and then report their counts. The keys asked about are therefore the keys the sketch itself estimated highest — which is to say, the keys where its error happened to be largest. That is not a sample of arbitrary queries; it is a sample deliberately enriched for the sketch’s own over-estimates, and the union bound has nothing to say about it because the queries depend on the same randomness the bound is over.
The effect has a direction and it is the unhelpful one. Count-Min never under-estimates, so selecting the top of its estimates selects keys whose piles of collision junk are unusually large, and the reported counts for exactly those keys are biased high by more than a randomly chosen key’s would be. The selection is doing the adversary’s work.
The standard repair is a second pass or a second structure: use the sketch to nominate candidates and something exact to count them, which is what a two-stage heavy-hitter pipeline does and why it exists. The repair is cheap because the candidate set is small. What is not available is a bound on the nominated keys’ estimates from the sketch alone, and a system that reports the sketch’s own numbers for the keys the sketch chose has used one structure for two jobs that need different guarantees.
What survives
Two sentences about a sketch are true without qualification and are worth separating from everything above, because the rest of this essay could be read as a case against the structures and is not.
The estimate is never below the truth. No probability, no stream dependence, no fine print — the property earned in a count that is never under, and the one that makes the number usable for anything at all.
The state does not grow. Eight kilobytes summarises a stream of any length over a universe of any size, and every alternative that is uniformly accurate is provably linear in something. Those two facts are what the structure is for. Everything else it is described as offering has conditions on it, and the conditions are in the formula rather than in a footnote.
It is worth saying why this essay exists at all, given that nothing in it is a correction to the literature. Every statement here is in the original papers, stated correctly, usually in the first page. What is being corrected is the transmission — the version that survives being repeated, in documentation, in blog posts, in the sentence a colleague says while recommending a structure. That version keeps the reassuring half of every clause and drops the qualifying half, and it does so consistently enough that the resulting mental model is predictable: uniformly accurate, confident overall, better with more data. All three are the reverse of the truth, and each of the three is one dropped phrase away from the paper.
Named alongside this one
Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.
- The items that survive k counters additive error · count-min sketch · estimator · guarantee · heavy hitter · one-sided error · sketch · state bits · zipf distribution
- The skew a few counters cannot repair estimator · heavy hitter · independence assumption · relative error · sketch · zipf distribution
- The join order is a guess estimator · heavy hitter · independence assumption · relative error · zipf distribution
- The state a merge is standing in for estimator · guarantee · heavy hitter · state bits · zipf distribution
- The summaries that add count-min sketch · estimator · guarantee · sketch · state bits
- A count read off the leading zeros estimator · relative error · sketch · state bits
What links here
The 8 essays that link to this one and share the most of its objects, of 12 that link here.
- A count that is never under
- A sketch that is allowed to be under
- The estimate that squares the stream
- The answer that is allowed to be wrong
- A promise about the rank is not a promise about the value
- The counter that takes the smallest slot
- The error that is on the rank
- The cheap tail and the expensive merge
The objects this essay names
Each one links to every other essay that touches it.
Additive errorCount-Min sketchEstimatorFailure probabilityGuaranteeHeavy hitterIndependence assumptionMedian of meansOne-sided errorRelative errorSketchState bitsZipf distribution