Skip to main content
On this page
Concepts/Algorithms & Data Structures

Bloom Filters

A Bloom filter is a space-efficient probabilistic data structure used to test set membership. It answers queries with "definitely not in set" (zero false negatives) or "probably in set" (with a tunable false positive rate). By eliminating expensive disk reads and database scans for non-existent keys, Bloom filters protect high-throughput databases like Cassandra, RocksDB, and HBase.

Key takeaway: Bloom filters have zero false negatives: if the filter returns false, the item is 100% guaranteed not to exist. Use them as an in-memory guard rail to bypass expensive disk I/O and network hops.

Disk I/O is 10,000x slower than RAM. In high-throughput databases, querying disk for keys that do not exist destroys throughput. Bloom filters sit entirely in memory, rejecting non-existent keys in sub-microseconds.

Deep Dive & Production Considerations

1. How It Works

A Bloom filter is a space-efficient probabilistic data structure used to test whether an element is a member of a set. It answers queries with either "definitely not in set" (100% certainty) or "probably in set" (a small, mathematically tunable false positive probability).

It consists of a bit array of size m (initially all set to 0) and k independent hash functions. When you add an item (e.g., "apple"):

  1. Pass "apple" through the k hash functions to calculate k array bit indices.
  2. Set the bits at all k positions to 1.

To check if an item exists, hash it through the same k functions:

  • If any of the resulting bits is 0, the element is definitely not in the set (zero false negatives).
  • If all bits are 1, the element is probably in the set (other keys may have set those bits via collisions).

2. The Bit Array Mechanics

[ 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 ]  <-- Empty Bit Array (m = 8)

1. Add "apple"  -> Hash1 = 1, Hash2 = 5
[ 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 ]

2. Add "banana" -> Hash1 = 3, Hash2 = 5
[ 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 ]

3. Check "cherry" -> Hash1 = 1, Hash2 = 6
Index 6 is '0' -> DEFINITELY NOT IN SET (Disk read skipped!)

3. False Positives & Sizing Mathematics

Because multiple keys can set the same bit positions, query collisions produce false positives. However, the false positive rate is mathematically tunable based on the bit array size (m) and element capacity (n):

  • Rule of Thumb: Allocating 10 bits per item (m/n = 10) with k = 7 hash functions yields a false positive rate of less than 1%, regardless of whether the set contains 1 million or 1 billion items.
  • Deletions are Impossible: In a standard Bloom filter, you cannot delete an element by resetting bits to 0 because doing so would inadvertently delete other keys that share those bits. (Systems requiring deletion use Counting Bloom Filters or Cuckoo Filters).

4. Real-World Systems Use Cases

  • Databases & Storage Engines (Cassandra, RocksDB, HBase): Query an in-memory Bloom filter before seeking an on-disk SSTable. If the filter returns false, an expensive disk read is avoided entirely.
  • Content Delivery Networks (Akamai): Prevent "one-hit wonders" (assets requested only once) from polluting SSD caches. An asset is only cached on disk upon its second appearance.
  • Web Security (Google Chrome): Checks URLs against a local in-memory Bloom filter of known malicious websites before making network queries to Google servers.

© 2026 abstractalgorithms.dev • Brutalist Editorial Architecture

Designed for clarity • Zero bloat