Bloom Filter
By Ankur NayakReviewed
A Bloom filter is a compact bit array that answers 'is this key in the set?' with either 'definitely not' or 'probably yes'. It never gives false negatives, uses a few bits per key, and lets a system skip expensive lookups for keys that don't exist. Cloudflare's Quicksilver answers 99% of its negative lookups this way, without touching disk.
How it works
Start with an array of m bits, all zero, and k hash functions. To add a key, hash it k times and set those k bits. To check a key, hash it the same way: if any of the k bits is zero, the key was never added; if all are one, it probably was, though the bits may have been set by other keys (a false positive).
The false-positive rate depends on bits per key and the number of hash functions, not on key size, so a filter for billions of keys can fit in memory. Deleting is not supported in the basic form, because clearing a bit could remove other keys; variants such as counting filters or cuckoo filters handle deletions at extra cost.
Cloudflare's 2025 description of Quicksilver v2 shows why this matters: it sees about ten times more lookups for keys that don't exist than for keys that do, and 99% of those negative lookups are answered by the in-memory Bloom filter. For 5 billion keys, the team found a Bloom filter needs about 6 GB for its target false-positive rate, versus about 18 GB for a comparable cuckoo filter.
Key points
- Answers: definitely not, or probably yes
- No false negatives; tunable false positives
- A few bits per key, independent of key size
- Skip disk or network lookups for missing keys
- Basic form can't delete keys
When to use it, and pitfalls
Use it for
- In front of a disk or remote store with many lookups for missing keys
- Storage engines checking whether a file might contain a key
- Deduplication and 'have I seen this before?' checks where rare false positives are acceptable
Watch out for
- Undersizing: the false-positive rate climbs quickly as the filter fills
- Using it where a false positive is harmful without a follow-up exact check
- Needing deletions with a plain Bloom filter
Trade-offs
Bloom vs cuckoo filter
Use a Bloom filter when keys are only added; a cuckoo filter when you need deletions.
Pros: Bloom: simple and compact (6 GB vs 18 GB for 5B keys at Cloudflare); Cuckoo: supports deletes
Cons: Bloom: no deletes; Cuckoo: more memory at the same false-positive rate in that case
Used in
Related building blocks
Frequently asked questions
Can a Bloom filter give a false negative?
No. If a key was added, all of its bits were set and stay set, so the filter will always say 'probably yes' for it. It can only give false positives: saying a key might be present when it never was.
Why use a Bloom filter in front of a database?
Lookups for keys that don't exist still cost a disk read or network call. A Bloom filter in memory answers most of them immediately. Cloudflare's Quicksilver answers 99% of negative lookups this way.