Chaturmind
LearnDSASystem DesignDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Low-Level Design & Design Patterns

OOP Fundamentals & SOLID Principles

  • Object-Oriented Design Refresher
  • Single Responsibility & Open/Closed
  • Liskov Substitution & Interface Segregation
  • Dependency Inversion

Creational Design Patterns

  • Singleton Pattern
  • Factory & Abstract Factory
  • Builder Pattern
  • Prototype Pattern

Structural Design Patterns

  • Adapter & Facade
  • Decorator Pattern
  • Composite & Proxy
  • Bridge & Flyweight

Behavioral Design Patterns

  • Strategy Pattern
  • Observer Pattern
  • Command Pattern
  • Template Method
  • State Pattern
  • Chain of Responsibility
  • Iterator & Mediator
  • Visitor Pattern

Machine Coding Exercises

  • Parking Lot — Requirements & Class Design
  • Parking Lot — Implementation
  • Elevator System — Requirements & Class Design
  • Elevator System — Implementation & Scheduling
  • Library Management System
  • Tic-Tac-Toe / Board Game Design
  • Chess Engine Design
  • Vending Machine Design
  • ATM System Design
  • In-Memory Rate Limiter
  • Thread-Safe LRU Cache
  • Connection Pool Design
  • Producer-Consumer Class Design
  • Movie Ticket Booking System
  • Hotel Reservation System
  • Airline Booking / Seat Selection System
  • Splitwise / Expense Sharing System
  • Design a Logging Framework
  • Design a Notification/Observer-Based Pub-Sub
  • Design a Cache with Pluggable Eviction Policy
  • Design Snake and Ladder
  • Design a Card Game Framework
  • Design an Inventory Management System
  • Restaurant Management System
  • Food Delivery Order Matching
  • Design a Shopping Cart & Checkout Flow
  • Design a Recommendation Engine
  • Design a Job Scheduler
  • Design a Circuit Breaker
  • Design a Distributed ID Generator
  • Design a Pub-Sub Message Broker
  • Design Twitter/X
  • Multi-Pattern Problem: Design a Ride Booking Class Model
  • Multi-Pattern Problem: Design a Food Ordering Class Model
  • Design an Authentication/Authorization Module
  • Design a Form/Survey Builder
  • Design a Meeting Room / Calendar Booking System
  • Design a Search/Filter Engine for an E-Commerce Catalog
  • Design a Voting/Polling System
  • Design a Retry Mechanism with Backoff
  • Design a Health Check Aggregator
  • Design a Feature Flag System
  • Design a Config Management Client
  • Design a Leader Election Algorithm
  • Design a Distributed Counter
  • Design a Bloom Filter
  • Design a Consistent Hashing Ring
  • Design a Distributed Tracing Library
  • Design a Metrics Collection Library
  • Design an Audit Logging Framework
  • Design a Plugin/Extension System
  • Design a Workflow Engine
  • Multi-Pattern Capstone: Design a Food Delivery App
Chaturmind
← Low-Level Design & Design Patterns

OOP Fundamentals & SOLID Principles

  • Object-Oriented Design Refresher
  • Single Responsibility & Open/Closed
  • Liskov Substitution & Interface Segregation
  • Dependency Inversion

Creational Design Patterns

  • Singleton Pattern
  • Factory & Abstract Factory
  • Builder Pattern
  • Prototype Pattern

Structural Design Patterns

  • Adapter & Facade
  • Decorator Pattern
  • Composite & Proxy
  • Bridge & Flyweight

Behavioral Design Patterns

  • Strategy Pattern
  • Observer Pattern
  • Command Pattern
  • Template Method
  • State Pattern
  • Chain of Responsibility
  • Iterator & Mediator
  • Visitor Pattern

Machine Coding Exercises

  • Parking Lot — Requirements & Class Design
  • Parking Lot — Implementation
  • Elevator System — Requirements & Class Design
  • Elevator System — Implementation & Scheduling
  • Library Management System
  • Tic-Tac-Toe / Board Game Design
  • Chess Engine Design
  • Vending Machine Design
  • ATM System Design
  • In-Memory Rate Limiter
  • Thread-Safe LRU Cache
  • Connection Pool Design
  • Producer-Consumer Class Design
  • Movie Ticket Booking System
  • Hotel Reservation System
  • Airline Booking / Seat Selection System
  • Splitwise / Expense Sharing System
  • Design a Logging Framework
  • Design a Notification/Observer-Based Pub-Sub
  • Design a Cache with Pluggable Eviction Policy
  • Design Snake and Ladder
  • Design a Card Game Framework
  • Design an Inventory Management System
  • Restaurant Management System
  • Food Delivery Order Matching
  • Design a Shopping Cart & Checkout Flow
  • Design a Recommendation Engine
  • Design a Job Scheduler
  • Design a Circuit Breaker
  • Design a Distributed ID Generator
  • Design a Pub-Sub Message Broker
  • Design Twitter/X
  • Multi-Pattern Problem: Design a Ride Booking Class Model
  • Multi-Pattern Problem: Design a Food Ordering Class Model
  • Design an Authentication/Authorization Module
  • Design a Form/Survey Builder
  • Design a Meeting Room / Calendar Booking System
  • Design a Search/Filter Engine for an E-Commerce Catalog
  • Design a Voting/Polling System
  • Design a Retry Mechanism with Backoff
  • Design a Health Check Aggregator
  • Design a Feature Flag System
  • Design a Config Management Client
  • Design a Leader Election Algorithm
  • Design a Distributed Counter
  • Design a Bloom Filter
  • Design a Consistent Hashing Ring
  • Design a Distributed Tracing Library
  • Design a Metrics Collection Library
  • Design an Audit Logging Framework
  • Design a Plugin/Extension System
  • Design a Workflow Engine
  • Multi-Pattern Capstone: Design a Food Delivery App
HomeLearnSystem DesignLow-Level Design & Design PatternsMachine Coding Exercises
✓ FreeIntermediate· 7 min read

Design a Bloom Filter

A bit-array-plus-multiple-hash-functions implementation, tuning false-positive rate via array size and hash count, why false negatives are structurally impossible, and real production uses from web crawlers to Cassandra's SSTables.

Published September 23, 2026


Design a Bloom Filter

Implementation: bit array + multiple hash functions

class BloomFilter {
    BitSet bits;
    int size; // m: bit array size
    int hashCount; // k: number of hash functions

    BloomFilter(int size, int hashCount) { this.bits = new BitSet(size); this.size = size; this.hashCount = hashCount; }

    void add(String item) {
        for (int i = 0; i < hashCount; i++) {
            bits.set(hash(item, i) % size); // set k bits, one per hash function
        }
    }

    boolean mightContain(String item) {
        for (int i = 0; i < hashCount; i++) {
            if (!bits.get(hash(item, i) % size)) return false; // ANY unset bit means DEFINITELY not present
        }
        return true; // all k bits set -> POSSIBLY present (or a false positive)
    }

    private int hash(String item, int seed) { /* a family of k independent-enough hash functions */ }
}

Adding an item sets k bits (one per hash function); checking membership verifies ALL k corresponding bits are set. This is the entire mechanism — no actual items are ever stored, only bit positions, which is what makes a Bloom filter dramatically more space-efficient than storing the actual items in a HashSet.

Why false negatives are structurally impossible

If an item was actually added, EVERY one of its k bits was explicitly set at that time — those bits can only ever be set (never cleared, in a basic Bloom filter), so a later check for that same item will always find all k bits still set, and mightContain will correctly return true. A false positive happens when a DIFFERENT combination of other items' bit-settings happens to have set ALL of a given item's k positions anyway, even though that specific item was never added — this is the only kind of error a Bloom filter can produce; "definitely not present" (any single bit unset) is always a mathematically guaranteed CORRECT answer.

Tuning the false-positive rate

Optimal hash function count:  k = (m/n) * ln(2)
  where m = bit array size, n = expected number of elements to be added

More bits (larger m relative to expected element count n) lowers the false-positive rate but costs more memory; more hash functions (k) up to the optimal point ALSO lowers the false-positive rate (spreading each item across more positions makes accidental full-overlap less likely), but too many hash functions past the optimum actually starts INCREASING the false-positive rate again (the bit array fills up faster, making collisions more likely) — this formula gives the sweet spot for a given size/expected-count combination, and an interviewer asking you to REASON about this trade-off (more bits = fewer false positives, at a real memory cost) matters more than memorizing the exact formula.

Real production uses

  • Web crawler deduplication (Web Crawler): before crawling a URL, check a Bloom filter of already-seen URLs — a false positive means occasionally SKIPPING a URL that was actually new (a minor, acceptable cost), while the massive space savings versus storing every full URL in a HashSet is the entire point.
  • Cache miss avoidance: checking a Bloom filter BEFORE an expensive cache/database lookup for a key that might not exist — if the filter says "definitely not present," skip the expensive lookup entirely; only a possible-positive triggers the real, more expensive check.
  • Cassandra/HBase SSTables: each on-disk SSTable file keeps a Bloom filter of the keys it contains — before reading a file from DISK to check for a key, the database first checks the (in-memory) Bloom filter, avoiding an unnecessary, slow disk read for keys that provably aren't in that particular file.

Follow-up questions this topic invites — and their answers

Q: Can a standard Bloom filter support removing an item? A: No — clearing a bit to 'remove' an item could incorrectly cause a DIFFERENT item (that happens to share that bit position) to suddenly report as absent, violating the no-false-negatives guarantee; a Counting Bloom Filter variant (using small counters instead of single bits, incremented/decremented rather than just set) supports removal at the cost of more memory per position.

Q: Why not just use a HashSet if you have enough memory for it? A: At sufficient scale, a HashSet storing actual keys/URLs can require orders of magnitude more memory than a Bloom filter's compact bit array — a Bloom filter trades a small, tunable false-positive RATE for a dramatic memory reduction, which is exactly the right trade for use cases (crawler dedup, cache-miss avoidance) where an occasional false positive costs almost nothing.

Q: How would you decide the expected element count (n) for sizing the filter, if you don't know it in advance? A: Either over-provision based on a reasonable upper-bound estimate (accepting some wasted space if actual count comes in lower), or use a SCALABLE Bloom filter variant that adds additional filter layers as the actual element count grows past initial sizing — a genuine practical concern when the true element count is hard to predict upfront.

Q: Is a Bloom filter's k-independent-hash-functions requirement hard to satisfy in practice? A: In practice, a single good hash function combined with a technique like double hashing (deriving k effectively-independent hash values from just two base hash computations) is commonly used instead of implementing k truly separate hash functions from scratch — a practical engineering shortcut that achieves close to the same statistical behavior with much less implementation complexity.

Previous

Design a Distributed Counter

Next

Design a Consistent Hashing Ring

AI Tutor

Lesson: Design a Bloom Filter

Quick actions

AI responses can be inaccurate. Verify critical information.