Skip to the guide

Bloom filters, HyperLogLog and count-min sketch

IntermediateConcept3 pages

Three questions come up again and again at scale: "have we seen this before?", "how many different ones?" and "how often does each appear?". These three structures answer them in kilobytes or megabytes instead of gigabytes, with an error you choose. Interviewers expect you to size them and say which way each one can be wrong.

The festival gate

A four-day music festival has 200,000 visitors, and the gate staff can't check a full list for every wristband. For blocked wristbands, a board of lights: each blocked number switches on three lights picked from its digits. If any of a wristband's three lights is off, it's certainly not blocked; if all are on, it might be, so they check the list. For the organisers' question "how many different people came?", an estimate within 1% is good enough. And for "which food stall sells the most?", a rough tally that can run a little high, but never low, is enough to pick the top ten.