Your database has a billion URLs. A user asks: "have we seen this URL before?" A hash set answers exactly — and costs 50 GB of RAM. A Bloom filter answers almost exactly, is wrong 1 time in 100, and costs 1.2 GB. That 42x saving is the entire idea of probabilistic data structures: trade a small, quantified chance of being wrong for an order of magnitude less memory — and arrange the error so it can only ever fail in the safe direction.
This is Season 3, Part 5. Part 4 built the inverted index for search; this part builds the structure that sits in front of almost every database, cache, and crawler in production — the one that says "definitely not" with certainty and "probably" the rest of the time.
The ELI5 version
Imagine a bouncer with a cheat sheet: a row of light switches, all off. When a guest arrives for the first time, the bouncer runs their name through three different hash recipes, and each recipe points at one switch. He flips those three switches on.
Now a stranger shows up. The bouncer runs the same three recipes on the stranger's name and checks the three switches. If any switch is off, the stranger was definitely never here — no guest could have left that switch off. If all three are on, the stranger might have been here — or three other guests might have coincidentally flipped exactly those switches. The bouncer can never wrongly turn away a real guest, but he sometimes waves in a stranger. That is a Bloom filter: false positives possible, false negatives impossible.
The cheat sheet is the whole data structure: m bits and k hash functions. Burton Bloom published it in 1970, and it has been in production ever since because the trade is so good.
How it works: three formulas
Insert x: set bits h1(x), h2(x), …, hk(x) to 1. Query x: if all k bits are 1, answer "maybe"; if any is 0, answer "definitely not". That's it — there is no delete, no iteration, no stored keys. The filter never holds a single element; it holds a shadow of the set.

The false-positive rate follows from one probability. After inserting n elements with k hashes into m bits, the chance a given bit is still 0 is (1 − 1/m)^(kn) ≈ e^(−kn/m). A false positive needs all k of a stranger's bits to be 1, so:
p ≈ (1 − e^(−kn/m))^k
Two derived formulas do all practical sizing. The optimal number of hashes for a fixed bits-per-element is k = (m/n) · ln 2 ≈ 0.693 · (m/n) — and at that optimum exactly half the bits are set, which is the filter's sweet spot. Substituting back gives the cleanest form in the field:
p ≈ 0.6185^(m/n)
Read it as: every extra bit per element multiplies the false-positive rate by 0.6185. Or in the form you size with: each +4.8 bits per element divides false positives by 10. The notebook measures all of this on a real filter: 100,000 keys at a 1% design point (m = 958,505 bits, k = 7) came back with measured FPR 1.00% against a formula prediction of 1.00%, zero false negatives, and the array 51.8% full — the theory is not approximate here, it's exact to measurement.

The sizing table you actually use
Design runs backwards from the target rate. Pick p, compute bits per element m/n = −ln(p) / (ln 2)², round k = (m/n) ln 2 to the nearest integer (the curve is flat near the optimum, so being one off costs almost nothing):
| Target FPR | Bits per element | Optimal k | 1M keys | 1B keys |
|---|---|---|---|---|
| 10% | 4.79 | 3 | 0.60 MB | 0.60 GB |
| 1% | 9.59 | 7 | 1.20 MB | 1.20 GB |
| 0.1% | 14.38 | 10 | 1.80 MB | 1.80 GB |
| 0.01% | 19.17 | 13 | 2.40 MB | 2.40 GB |
| 0.001% | 23.96 | 17 | 3.00 MB | 3.00 GB |
Two things to internalize. First, the cost of certainty is logarithmic: going from 1% to 0.001% false positives costs 14 extra bits per key, not 1,000x the memory. Second, the filter's size depends only on how many elements you insert, never on how big they are — a billion 50-byte URLs and a billion 5 KB documents cost the same 1.2 GB at 1%. That is why the structure shows up wherever keys are big and counts are huge.

Where it lives in production
Databases — the SSTable skip. This is the canonical deployment, and the numbers are the reason. Cassandra, Bigtable, and ScyllaDB keep one Bloom filter per SSTable on disk. A read for a key that lives in exactly one of 100 SSTables would otherwise touch all 100; with a 1% filter it touches 1 + 99 × 0.01 ≈ 2 SSTables — 50x fewer disk reads. The 1% of reads that check a wrong SSTable cost one wasted seek; the 99% that skip 99 SSTables are the whole point. LSM-tree engines (RocksDB, LevelDB) do the same per SSTable, and Parquet row-group filters do the same per row group.
Browsers — Safe Browsing. Chrome keeps a local Bloom filter of known-malicious URLs (tens of megabytes, updated regularly). Every navigation checks the filter locally: a miss means safe with certainty and no network call; a hit means "maybe" and only then does Chrome ask Google's servers. The filter turns a privacy-sensitive lookup on every page load into a local bit test.
Crawlers and caches. A web crawler with a billion-URL frontier keeps the seen-set as a Bloom filter instead of a hash set — 50 GB vs 1.2 GB, same decision. CDNs and caches use them to avoid asking a backend for keys that were never stored. Apache Spark uses Bloom filters in broadcast joins to skip shuffling rows that can't match.
The pattern to recognize: a Bloom filter belongs anywhere the question is "have we seen this before?" and the cost of a wrong yes is one wasted lookup, while the cost of a wrong no would be catastrophic. If a wrong no is acceptable too, you don't need the asymmetry — and if a wrong yes is expensive (say, it triggers a $10 API call), you size the filter tighter or don't use one.
Why it breaks: four failure modes
Overfill. A Bloom filter is sized for a specific n, and the false-positive rate explodes past it. The notebook measures it on the same 1%-designed filter: at design capacity the rate is 1%; at 1.5x capacity it's 5.7%; at 2x it's 16%; at 3x it's 43% — nearly half of all absent-key lookups returning "maybe". The filter doesn't degrade gracefully; it degrades exponentially, because every extra key sets k more bits and the fill ratio climbs toward 1. The fix is sizing for the maximum n, not the average — or rebuilding the filter when the count grows.

No deletes. Setting a bit to 0 might un-insert other elements that share it, so plain Bloom filters can't delete at all. The fixes are well known: a counting Bloom filter replaces each bit with a small counter (typically 4 bits) so deletes decrement instead of clearing — at 4x the memory; or a Cuckoo filter (Fan et al., 2014), which stores short fingerprints in cuckoo-hash buckets, supports deletion, and beats Bloom on space for false-positive rates below ~3%. If your set churns, pick one of those from the start — retrofitting deletion onto a plain filter is how you get silent corruption.
Hash quality. The formulas assume uniform, independent hashes. A weak hash (or an attacker who knows your hash function and crafts colliding inputs) breaks the independence assumption and the measured rate drifts far above the formula. Production filters use a strong hash or double-hashing from one good hash; if the input is adversarial — user-controlled keys — treat the hash choice as a security decision, not a performance one.
The wrong n, or the wrong question. Size for the n you'll actually reach, including growth, and remember what the filter can't answer: it can't list members, count them, or return the element — it's a membership test only. Teams that reach for a Bloom filter when they need a set usually discover this the week they need to iterate. HyperLogLog counts distinct elements; Count-Min Sketch counts frequencies; a Bloom filter answers one question, and answers it well.
The family: three structures, three questions
Bloom filters are the middle child of the probabilistic family, and the interview answer is knowing which sibling answers which question:
| Structure | Question | Memory for 1B items | Error |
|---|---|---|---|
| Bloom filter | Is x in the set? | ~1.2 GB at 1% FPR | False positives only |
| HyperLogLog | How many distinct items? | ~12 KB | ±0.8% standard error |
| Count-Min Sketch | How many times did x appear? | ~MBs, tunable | Overestimates only |
All three share the same deal — fixed tiny memory, quantified error, never a false negative in the direction that matters — and all three show up in the same systems: HyperLogLog behind Redis's PFCOUNT and BigQuery's APPROX_COUNT_DISTINCT, Count-Min Sketch behind heavy-hitter detection in stream processors, Bloom filters in front of the disk.
The interview angle
"Design a URL shortener" or "design a web crawler" are the classic Bloom filter prompts, and the strong answer starts with the arithmetic, not the structure. A billion URLs at 50 bytes is 50 GB as a hash set — too big to hold, and the interviewer knows it. The Bloom filter at 1% is 1.2 GB, and the follow-up writes itself: what does the 1% cost you? One wasted disk read in a hundred, or one redundant crawl fetch in a hundred — and what do you do when the crawler's seen-set grows past the design capacity? (Rebuild with a bigger m, or size for the max from the start.) The separators: deriving k = (m/n) ln 2 instead of reciting it, naming the no-delete limitation unprompted, and reaching for a Cuckoo filter when the interviewer adds deletion to the requirements.
Takeaways
- A Bloom filter trades a quantified false-positive rate for 42x less memory: 1 billion keys at 1% FPR cost 1.2 GB, not 50 GB — and the size depends only on count, never on key size.
- The whole design is three formulas: p ≈ (1 − e^(−kn/m))^k, k_opt = (m/n) ln 2, and p ≈ 0.6185^(m/n) — every +4.8 bits per element buys a 10x lower rate.
- The asymmetry is the point: false positives possible, false negatives impossible. It belongs wherever a wrong "yes" costs one wasted lookup and a wrong "no" would be catastrophic.
- In production it sits in front of disk: Cassandra/Bigtable SSTable filters turn 100 disk reads into ~2; Chrome Safe Browsing turns a network call into a local bit test.
- It breaks by overfill, not by age: 1% FPR at design capacity becomes 43% at 3x capacity — size for the maximum n, and pick a counting Bloom or Cuckoo filter if the set needs deletes.
Follow for the next part — Season 3, Part 6 is data lakes vs warehouses vs lakehouses, and Part 7 follows a request across 50 services with distributed tracing. More on dev.to: @danielsamfdo.