Probabilistic data structures

Hand-drawn three hatched terracotta squares, each inside a loose cream outline, set in a flowing river of cream, sand, umber and moss pen lines.

A probabilistic data structure answers a question approximately, with an error it can bound, in exchange for much less memory or time than an exact answer would need. The main families answer different questions. Membership filters say whether a key might be in a set, distinct-count sketches estimate how many different keys arrived, and frequency sketches estimate how often a key occurred. Quantile sketches estimate a value at a given rank, such as the 99th percentile of latency, and similarity sketches find sets that overlap.

The disputes are mostly about measurement. Filter rankings change with the processor, cache residency and vector instructions, and quantile sketch rankings reverse depending on which error is measured and on the input distribution (Lang et al., 2019; Schmidt et al., 2021; Fernando et al., 2023; Łukasiewicz et al., 2025).

Membership filters

A membership filter answers “possibly in the set” or “definitely not in the set”. A wrong “possibly” is a false positive, and it usually sends the lookup on to a slower exact check. The first choice between filters is which operations they must support, because the most compact filters cannot change once built. Speed and space come second, and their ranking depends on the hardware.

What each filter can do

Bloom filters accept new keys at any time, but their false-positive rate rises as more keys go in (Graf & Lemire, 2022). Cuckoo and quotient filters also allow deletion, while xor, binary fuse and the tested Ribbon filters are static: they must see the complete set when they are built (Dillinger et al., 2022; Graf & Lemire, 2022).

A Bloom filter can be made to support deletion by replacing each bit with a 4-bit counter, at a substantially higher space cost. A quotient filter can also grow or shrink from the fingerprints it stores, without rehashing the original keys (Bender et al., 2012). Deletion in a cuckoo filter assumes the item was inserted. In Redis, deleting a value that was never inserted can cause false negatives: answers of “not present” for keys that are present (Redis, n.d.b).

Speed against space in static filters

Among static filters, blocked Bloom filters answer queries fastest, while Ribbon and binary fuse filters use the least space for a given false-positive rate. In a 100-million-key benchmark with 25% hits, blocked Bloom was fastest to query, followed by xor and binary fuse. Ribbon and binary fuse were more space-efficient than blocked Bloom, ordinary Bloom and a vector quotient filter at the same measured false-positive probability (Graf & Lemire, 2022).

The size of the space gap is large. Overhead here means space beyond the theoretical minimum for the chosen false-positive rate. At a false-positive rate of about 2^-8 (0.39%), the BuRR variant of Ribbon needed 0.2–1.4% overhead in one large parallel benchmark. It needed below 2% in a later one on 100 million keys. Blocked Bloom used around 50% overhead and queried faster in both (Dillinger et al., 2022; Dietzfelbinger et al., 2026).

One newer design pushes the overhead lower at a cost in build time. A 2026 design, the ZOR filter, reports overhead below 1%, but it builds more slowly than four-way binary fuse and BuRR (Limasset, 2026).

Build time differs as well. Binary fuse filters can build twice as fast as xor filters, and in one experiment on an AMD processor they built faster than Ribbon (Graf & Lemire, 2022).

Hardware changes the ranking

Studies disagree on which filter is fastest, because the answer depends on cache residency, vector instructions and the filter’s size. Two comparisons found blocked Bloom filters fastest on large filters. One of them found xor filters better suited to smaller filters or lower false-positive rates (Schmidt et al., 2021; Lang et al., 2019).

Where the filter sits in the memory hierarchy decides close contests. With AVX2 vector instructions, register-blocked Bloom and cuckoo filters performed about the same while they fit in the L1 cache. Once the filter outgrew the L2 cache, blocked Bloom needed fewer cycles per lookup (Lang et al., 2019).

Vectorized code and data layout can reverse a ranking. At 100 million keys, xor filters led many unvectorized configurations, but vectorized Bloom and cuckoo filters took the lead. Without partitioning, xor lookups fell behind cuckoo except at very low false-positive targets. Splitting the work by key (radix partitioning) helped once filters exceeded the last-level cache, and xor gained most (Schmidt et al., 2021).

Single-threaded and parallel workloads can also differ. Xor shared the middle of the best time–space trade-off with one Ribbon variant when large inputs were processed sequentially, but not in the parallel workload (Dillinger et al., 2022). Specific instructions matter too: one benchmark left out a vector quotient filter on an AMD processor because it relies on an instruction that was slow there (Graf & Lemire, 2022).

Sizing, repeated queries and attackers

A filter sized for too few keys either loses accuracy or slows down. A fixed-size Bloom filter’s false-positive rate rises as keys are added (Graf & Lemire, 2022). A Redis Bloom filter instead grows by stacking subfilters, and a query may then have to check several layers before answering “not present” (Redis, n.d.a).

When the same absent keys are queried again and again, a filter that learns from its false positives can help. On highly skewed network traces, adaptive filters had false-positive rates one to two orders of magnitude lower than nonadaptive filters. A simple cache of recent false positives matched the strongest adaptive filters unless many distinct absent keys were queried relative to the set size (Mo et al., 2026b). When each key is queried once, adaptation brings nothing: an adaptive quotient filter behaved like a traditional one (Sabale et al., 2026).

An attacker who can choose keys may try to force false positives. A formal analysis showed that Bloom filters and insertion-only cuckoo filters can be protected by building them on keyed pseudorandom functions, hash functions that depend on a secret key (Filić et al., 2022). The hash tables article covers the related problem of hash flooding.

Distinct counting

HyperLogLog (HLL) estimates how many distinct keys a stream contains using a small, fixed array of registers, and its error shrinks with the square root of the number of registers. The original analysis gives a typical relative standard error of about 1.04 divided by the square root of the register count. It puts the memory for typical 2% accuracy at about 1.5 kilobytes, even above a billion distinct keys (Flajolet et al., 2007). Relative standard error is the usual spread of the estimate as a share of the true count.

HyperLogLog in production systems

Production systems publish different error measures for their HLL implementations. Redis documents a standard error of 0.81% in at most about 12 KB (Redis, n.d.c). Google BigQuery uses HLL++, an engineered version with a 64-bit hash, a sparse representation for small counts and a correction for bias at small counts. At its default precision, a sketch takes at most 32 KiB plus 30 bytes, with a typical 95% interval of ±1.15% (Google Cloud, 2026f).

The HLL++ changes fix weaknesses of the original. Most of the original estimator’s error at small counts came from overestimating, in Google’s simulations. The move to 64-bit hashes supports counts beyond one billion at the cost of one more bit per register (Heule et al., 2013).

An HLL sketch can be merged with others to count the union, but values cannot be deleted from it. BigQuery’s merge function computes the union count, and its sketches do not support deletion (Google Cloud, 2026c; Google Cloud, 2026f). An exact set gives both: Java’s HashSet returns its exact size and supports removing elements (Oracle, n.d.i).

In one 2017 Google demonstration on the same 320,825,029 rows, exact distinct counting took 4.1 seconds and approximate counting took 2.6 seconds (Hoffa, 2017).

Smaller successors to HyperLogLog

Several newer sketches report the same accuracy as HLL in less memory, but each figure comes from the team that designed the sketch. UltraLogLog reports 28% less space for the same information with its maximum-likelihood estimator, and 24% less with a faster one (Ertl, 2024). Its insertion benchmark used generated random numbers in place of real hash values, on one machine and one Java version (Ertl, 2024).

The other reported savings fall in a similar range. The ExaLogLog author reports 43% less memory than HLL for the same error (Ertl, 2025). HyperLogLogLog’s authors observed sketches roughly 40% smaller (Karppa & Pagh, 2022). Apache DataSketches reports its CPC sketch 41% smaller than its HLL sketch when serialized at comparable error, but slower to serialize and deserialize than each HLL variant (Apache DataSketches, n.d.b).

Merging sketches and moving them between systems

Sketches built separately can be combined, but a merge only works between compatible sketches. In one benchmark, sketches with sparse storage merged faster at small counts because they held less data (Ertl, 2025).

Compatibility rules differ by system. BigQuery requires all HLL++ sketches in a merge to have the same input type, and a merge of sketches at different precisions falls to the lowest precision (Google Cloud, 2026c). Apache DataSketches stores a short hash of the hashing seed in Theta and Tuple sketches to check that sketches can be combined (Apache DataSketches, n.d.h). Trino works on serialized Theta sketches built elsewhere and exposes the seed setting for sketches created with a custom seed (Trino, n.d.).

Merged sketches may need a different estimator. Apache DataSketches’ Java library switches to a different HLL estimator when a union does not qualify for its usual one (Apache DataSketches, n.d.g). The library also documents a distorted distribution of errors for small sketches, even after many observations (Apache DataSketches, n.d.c).

Theta sketches support more than union. Apache DataSketches Theta also supports intersection, difference and Jaccard similarity (Apache DataSketches, n.d.f).

Serialized sketches are format-specific. Apache DataSketches documents compact sketches that its C++ and Java implementations can read from each other, for sketch types both provide, but user-written serialization code must be ported (Apache DataSketches, n.d.a; Apache DataSketches, n.d.e). Google documents HLL++ exchange between BigQuery and sketches built with Dataflow, Apache Spark or ZetaSketch (Google Cloud, 2026f).

Frequency and heavy hitters

Frequency sketches estimate how often a key occurred, and heavy-hitter algorithms find the most frequent keys. The Count-Min sketch never undercounts and overcounts by a bounded amount. When counts are nonnegative, its estimate exceeds the true count by at most a chosen fraction ε of the total count of all keys. This bound holds with probability at least 1−δ, where δ is a chosen failure probability (Cormode & Muthukrishnan, 2005).

Counter-based algorithms such as SpaceSaving track candidate frequent keys directly, and their speed depends on the implementation. In a 2008 comparison, the linked-list version of SpaceSaving was the fastest counter implementation, but it used twice the space of the heap version on average (Cormode & Hadjieleftheriou, 2008). In a benchmark on retail data with a fixed memory budget, both SpaceSaving and Count-Min recovered all the true frequent items at every tested threshold (Manerikar & Palpanas, 2009).

Newer top-k designs

Newer top-k sketches report higher precision or throughput in their designers’ experiments on network traffic. HeavyKeeper’s authors report 99.99% top-k precision with more than 20 KB on a CAIDA packet trace (Gong et al., 2018). With 20 KB, the top 100 flows and ten million packets, Sketch-BF processed 20.5 million packets per second. SpaceSaving processed 10.0 million, HeavyKeeper 5.7 million and Count-Min with a heap 3.8 million (Lu et al., 2022).

Quantiles

A quantile sketch estimates the value at a given rank, such as the median or the 99th percentile of request latency. The sketches guarantee different kinds of error, and the kind decides which one fits. A rank error says how far the returned value’s rank is from the requested rank; a value error says how far the returned value is from the true value.

The main sketches bound different errors. Greenwald–Khanna gives a deterministic bound on additive rank error (Masson et al., 2019). KLL has an additive rank-error guarantee, and REQ a multiplicative rank-error guarantee (Fernando et al., 2023). DDSketch bounds the error in value: the absolute error is at most a chosen fraction α of the true quantile value, for positive values (Masson et al., 2019).

A small rank error can hide a large value error in the tail. In one two-million-request latency dataset, a rank accuracy of 0.005 at the 99th percentile could mean returning any value from 2 to 20 seconds (Masson et al., 2019). A basic DDSketch can grow to one bucket per input in the worst case. The published version caps the bucket count by collapsing the lowest buckets, including when a merge exceeds the limit (Masson et al., 2019).

Rankings depend on the error measure and the data

Studies disagree on which quantile sketch is most accurate, because each measures a different error on different data. In one experimental study, UDDSketch, a DDSketch variant, gave the lowest relative value error across the datasets (Fernando et al., 2023). Measured by rank error instead, DDSketch was 10 to 100 times worse than KLL in another team’s experiments (Łukasiewicz et al., 2025).

The position in the distribution matters. On a bimodal power-use dataset, KLL did relatively well around central quantiles but poorly in the long tail, where REQ configured for high ranks was most accurate (Fernando et al., 2023).

The t-digest sketch can fail on some inputs. Cormode and colleagues found cases where it is inaccurate even on independent, identically distributed samples. On a constructed distribution spanning a very wide range, its rank error at the 80th percentile was near −30 percentage points. When they narrowed the range, t-digest became more accurate than REQ again (Cormode et al., 2021).

Merging many partial sketches degrades accuracy. When 10,000 chunks were merged in a balanced tree, the errors of t-digest and of the new SplineSketch rose about five to ten times compared with streaming the data directly. The same study reports SplineSketch usually improving rank error over t-digest by a factor of 2 to 20 when given enough capacity (Łukasiewicz et al., 2025). In one Apache comparison, KLL with k=200 and t-digest with compression 100 serialized to about the same size (Apache DataSketches, n.d.d).

Similarity: MinHash and locality-sensitive hashing

MinHash estimates the overlap between two sets, and locality-sensitive hashing (LSH) uses such signatures to find likely similar pairs without comparing every pair. Overlap here is Jaccard similarity: the size of the intersection divided by the size of the union. Under a random permutation, the smallest items of two sets match with probability equal to their Jaccard similarity (Jafari et al., 2021). MinHash-LSH splits these signatures into bands to produce candidate pairs with high overlap, which can then be checked exactly (Mao et al., 2026d).

One application is finding near-duplicate documents. In language-model training data, the NearDup pipeline found near-duplicates for 3.04% of C4 training examples and 13.63% of RealNews training examples. In C4, 77% of the examples it removed also shared at least one exact 50-token match with another document (Lee et al., 2022a). Lexical overlap misses rewrites that keep the meaning: in one benchmark, hashes built from a text-embedding model held up better under compression and rewriting, at a higher computing cost (Mao et al., 2026d).

LSH against graph indexes for vectors

For nearest-neighbour search over vectors, studies disagree on whether graph indexes or LSH indexes are faster at high recall. Recall is the share of the true nearest neighbours that the search returns. In the ANN-Benchmarks comparison on GloVe word vectors, the graph index HNSW had the highest throughput at high recall, and the LSH-based FALCONN was best at lower recall (Aumüller et al., 2017). In its authors’ later benchmark with 64 threads, Falconn++ exceeded two HNSW implementations in throughput from recall 0.97 on one dataset and 0.94 on another (Pham & Liu, 2022).

Further reading

  • Graf and Lemire, “Binary fuse filters: Fast and smaller than xor filters” (Graf & Lemire, 2022): a benchmark of Bloom, blocked Bloom, xor, binary fuse, Ribbon and quotient filters on space, build time and query time.
  • Schmidt, Bandle and Giceva, “A four-dimensional analysis of partitioned approximate filters” (Schmidt et al., 2021): a comparison showing how vectorization, partitioning and filter size change the ranking.
  • Flajolet and colleagues, “HyperLogLog” (Flajolet et al., 2007), with Heule, Nunkesser and Hall’s engineering follow-up (Heule et al., 2013): the original distinct-count analysis and the changes production systems adopted.
  • Cormode and Hadjieleftheriou, “Finding frequent items in data streams” (Cormode & Hadjieleftheriou, 2008): a comparison of counter-based and sketch-based heavy-hitter algorithms.
  • Cormode, Mishra, Ross and Veselý, “Theory meets practice at the median” (Cormode et al., 2021): worst-case inputs for t-digest and relative-error quantile sketches.
  • Lee and colleagues, “Deduplicating training data makes language models better” (Lee et al., 2022a): MinHash near-duplicate detection applied to language-model training data.

Known gaps

What this article cannot tell you yet.

  1. Reservoir sampling and weighted stream sampling were not researched.
  2. Independent tests of the newer distinct-count sketches (UltraLogLog, ExaLogLog, HyperLogLogLog) and of the newer top-k designs (HeavyKeeper, Sketch-BF) were not researched; their figures come from their designers.
  3. No benchmark compares filter families across processors, hit rates and implementations under matched conditions, so the crossover points between filters cannot be carried from one system to another.
  4. Count Sketch was not compared with Count-Min at matched memory in a recent benchmark.
  5. The quantile sketch studies measure memory and error in different ways, and SplineSketch has not been tested independently.
  6. The measured accuracy of merged HyperLogLog sketches under different union estimators was not researched.
  7. The memory saved by Bloom-filter variants of MinHash indexes was not researched.
  8. The study of adaptive filters versus caching recent false positives is known from its abstract.

References

Solid source
Rated highly trustworthy by the research, and every passage taken from it was found in it.
Weak source
Rated low, or a passage taken from it was not found in it.
Medium trust
Rated medium by the research.
Not checked
Rated high, but its passages could not all be checked against it.
Show all 45 references