Skip to content

Bloom filter

A Bloom filter screens set membership with definite negatives and possible positives. Follow a bit-array example, the false-positive approximation and safe trade-ID checks.

A Bloom filter is a compact probabilistic data structure that tests whether a key belongs to a set. It can answer definitely absent or possibly present. In a market-data pipeline, that asymmetry can save expensive lookups for unseen identifiers while sending possible matches to an exact store for verification.
Unlike a hash table, a standard Bloom filter does not retain the keys or their values. It cannot return a trade record or list the identifiers inserted. Bloom's original paper frames the trade-off as a small memory-resident screen followed, when necessary, by a more expensive test.

How a collision becomes a “maybe”

Start with mm zero bits. Use kk repeatable hash mappings from each key to bit positions. Insertion sets those positions to one; querying checks the same positions. One zero is enough to reject membership. All ones mean a possible match, because other keys may have set those bits.

Take ten bits indexed 0–9 and two positions per key. These positions are assigned for teaching, rather than generated by cryptographic hashes or independent uniform draws.
ActionPositions checked or setResult
Insert A1 and 4Set both bits to one
Insert B4 and 7Bit 4 stays one; set bit 7
Query absent C1 and 7Both one: false positive
Query absent D1 and 9Bit 9 is zero: definitely absent
Ten bits have ones at positions 1, 4 and 7 after inserting A at 1 and 4 and B at 4 and 7. Absent C checks 1 and 7 and returns maybe; absent D checks 1 and 9 and returns absent because bit 9 is zero.
Ten bits have ones at positions 1, 4 and 7 after inserting A at 1 and 4 and B at 4 and 7. Absent C checks 1 and 7 and returns maybe; absent D checks 1 and 9 and returns absent because bit 9 is zero.
The assigned positions expose the mechanism: C passes without ever having been inserted. A positive answer does not identify which keys set the bits.
The no-false-negative guarantee applies to successfully inserted keys queried with the same key encoding and hash mappings, with all required bits preserved. It does not cover missed updates, stale replicas, changed hashing, or corrupted storage.
Deletion is another boundary. Clearing A's bits would clear the shared bit 4 and make B fail its query. Ordinary bit clearing is unsafe. Counting Bloom filters use counters instead, with their own deletion and overflow requirements; see Broder and Mitzenmacher, §2.5.

What the false-positive rate measures

For nn distinct inserted keys, an ideal model with independent uniform hash placements gives the familiar approximation

pFP≈(1−e−kn/m)k.p_{\mathrm{FP}} \approx \left(1-e^{-kn/m}\right)^k.
A particular bit remains zero with probability (1−1/m)kn(1-1/m)^{kn} in that model. Approximating this by e−kn/me^{-kn/m} and approximating occupancy by its mean leads to the expression above. Broder and Mitzenmacher, §2.1 explain both approximations.
At m=10m=10, k=2k=2, n=2n=2, the expression gives 0.108688872…0.108688872\ldots, or approximately 10.9%. This is an illustration of the formula, not the exact probability for the fixed tiny table above. C's assigned outcome is certain; the example specifies no random distribution over absent keys.

The rate means “positive given that the queried key is absent.” It is not the fraction of positive answers that are wrong; that fraction also depends on how often queries are for absent keys. With fixed mm and kk, inserting more distinct keys fills more bits and increases false positives. The name has no connection to filtering a time series or trading signal.

Use it as a screen, with a consistent exact store

Consider a fictional ingestion service checking trade IDs for duplicates. A positive Bloom result should trigger an exact ID lookup. Dropping a trade solely because the filter says “present” would discard some new trades. A negative can skip that lookup only when the filter includes all relevant committed IDs. Concurrent ingestion still needs an exact uniqueness or idempotency mechanism: two workers can both check an ID before either inserts it.

Current Redis documentation illustrates the interface distinction: membership returns either “may exist” or “definitely does not exist,” while filter creation accepts an intended capacity and false-positive target. Those settings need workload planning; they do not make membership exact. The bit array is also neither an occurrence counter nor an encryption mechanism.
For exact collision resolution and expected lookup costs, Hash Tables: Chaining, Open Addressing, and Universal Hashing supplies the underlying comparison. Its public page is a preview; the full lesson requires membership.

Sources

Last updated
  • bloom filter
  • hashing
  • probabilistic data structures
  • set membership
  • false positives
  • data ingestion
← Back to the glossaryBack to top ↑