System Designcalculator

Probabilistic sketch sizer

A sketch answers a counting question in a fixed amount of memory by accepting a small, known error. HyperLogLog estimates how many distinct items you have seen. A count-min sketch estimates how many times each item has appeared.

Smaller than an exact set

12.29 KB counts 10,000,000 distinct items to within ±1.63% about 95% of the time, against 80 MB or more for an exact set.

Memory, dense12.29 KB16,384 registers × 6 bits
0.1%1%10%100%51015Precision (p)Standard errorp = 14

Inputs

Sketch
Work out

The sketch has 2^p registers.

Used for the 95% band and the exact-set comparison.

Standard error0.81%1.04 ÷ √registers
Likely range for 10,000,000 items9,837,500 to 10,162,500About 95% of estimates, ±1.63% (2σ)
Exact set, for comparison80 MB or more8 bytes per ID, before hash-table overhead (an assumption)

Each step of p doubles the memory and cuts the error by a factor of √2. The standard error holds for large counts. For small counts (well under the number of registers) HyperLogLog++ switches to linear counting and is usually more accurate.

What it shows

HyperLogLog hashes each item and records, in each of m registers, the longest run of leading zero bits it has seen. Long runs are rare, so they signal many distinct items. More registers mean a smaller error: 1.04 ÷ √m.

A count-min sketch is a grid of counters, d rows by w columns. Each row has its own hash, and an item adds one to one counter per row. A count is the smallest of its d counters, so it can be too high but never too low.

How to read it

  • For HyperLogLog, set the precision p or a target standard error. The sketch has 2^p registers of 6 bits each.
  • “Memory, dense” is the dense layout. Each step of p doubles memory and cuts error by √2, so halving the error costs four times the memory.
  • “Likely range” is the 95% band, two standard errors either side of the true count. Expect that spread; it is not a hard limit.
  • “Exact set, for comparison” assumes a fixed number of bytes per ID, before hash-table overhead.
  • For count-min, ε sets the width and δ the depth. The “Error bound” is ε × N, where N is the total of all counts added, so it grows with the stream, not the item.
  • Counter size sets memory per counter. The tool warns “Counters may overflow” if one count could pass what a counter holds.

Questions

Why does HyperLogLog use 6 bits per register?

Each register stores the position of the first 1 bit in a 64-bit hash, which never exceeds 64 and so fits in 6 bits. That is how Redis lays out its dense sketch: 16,384 registers of 6 bits, 12,288 bytes.

Can I merge two HyperLogLog sketches?

Yes, if they use the same precision and hash function. Take the larger value in each register, and the result is the sketch of the union. Count-min sketches merge by adding the two grids, again with matching size and hashes.

Why is a count-min estimate never too low?

Every item adds to its own counter in each row, so a counter holds at least the item’s true count plus whatever other items collided into it. The minimum across rows is the least inflated of those.

How accurate are these numbers?

The HyperLogLog error is the large-count figure from the paper, and the count-min bound holds for the sketch as described by Cormode and Muthukrishnan. Real libraries add bias correction for small counts, so their error there is usually lower. Heavy skew or a poor hash can make results worse.

Learn it properly

Sources

Last updated

More tools

All tools

Your first senior-level
lesson is free.

Choose a course, open a free lesson, and explore an idea you’ve wanted to understand.