Library / Documentation
Bloom filter (Wikipedia)
Definition, false-positive rate, sizing formulas and variants of Bloom filters.
By Wikipedia contributors · Wikipedia · Added 2026-10-12
All content belongs to Wikipedia contributors / Wikipedia. We only link to it and give credit. Report a problem
Learn this doc
About 30 min left. Your work is saved as you go.
What you want from these docs
Wikipedia documents a tool you may use. Decide what you want to do with it, then read only what answers that.
Ideas you will meet
- Distributed Systems
- Consensus, time, failure and the fundamentals of scale-out.
What we already know about this
Our own lessons on these ideas. Read them here before you start, so it makes sense.
Search, Analytics and Geo · 10 minSeen filtering: Bloom filter versus exact setsHow to avoid showing a user the same item twice in a feed or recommendation list, what a Bloom filter trades away, and how to size the memory.Read here
The problem
A feed, a recommendation list or a "discover" page should not show the same item twice. For each user we must answer, quickly, "has this user already seen item X?" for every candidate item, and record what they see. With millions of users and thousands of items each, memory becomes the main constraint.
100%Figure SDA-SAG-10-1 · Where seen filtering sits · © forcsguy.com
Option 1: exact sets
Keep, per user, the exact set of seen item ids: a Redis set, a sorted set with a time score so you can trim, or a bitmap if ids are small dense integers. Answers are always right. The cost is memory: 2,000 ids of 8 bytes is 16 KB per user, or about 1.6 TB for 100 million users.
Option 2: a Bloom filter per user
A Bloom filter is a bit array and several hash functions. To add an item, set the bits its hashes point to. To test, check those bits: if any is 0, the item was definitely not added; if all are 1, it was probably added.
- No false negatives: an item that was shown will never be shown again.
- A small chance of false positives: some fresh items are wrongly treated as seen, so they are skipped.
- For a 1 percent false-positive rate you need about 9.6 bits per item, so 2,000 items need about 2.4 KB per user, around 240 GB for 100 million users. That is 6 to 7 times smaller.
100%Figure SDA-SAG-10-2 · How a Bloom filter answers · © forcsguy.com
Sizing: with
nitems and false-positive ratep, use aboutm = -n x ln(p) / (ln 2)^2bits andk = (m / n) x ln 2hash functions.Before: exact set of ids
100%After: Bloom filter
100%What changed
- Memory per user drops by roughly ten times or more
- A small share of new items are wrongly treated as seen
- A filter cannot list or remove what it holds
Handling time
Standard Bloom filters cannot delete. Two common fixes:
- Rotating windows: keep one filter per day or week. Test against all of them; add to the newest; drop the oldest. This also expresses "seen in the last 30 days".
- Counting Bloom filters use small counters instead of bits so items can be removed, at several times the memory.
A filter can also be sized for the expected number of items; adding far more than planned makes false positives climb, so create a new filter instead of growing one forever.
Choosing
Need Choice Exactness, small sets, explicit "hide this" actions Exact sets Huge user base, soft rule, memory matters Bloom filter Many items per user over a long window Rotating Bloom filters Check across billions of items globally (for example crawled URLs) Partitioned Bloom filters Many systems use both: an exact set for the last few items and the explicit hides, and a Bloom filter for the long tail.
Real-world reading
Go deeper on this
A path through videos, articles, other case studies and code on the same ideas as Bloom filter (Wikipedia).
Warm upGet the vocabulary first.
Books · Free from the author
Concurrent and Distributed Systems (Cambridge lecture notes)
Eight lectures on time, broadcast, replication, consensus and transactions, with notes, slides and video. Free from the author under CC BY-SA.
University of CambridgeIntermediate
Books · Free from the author
Computer Networks: A Systems Approach
How networks are built and why: protocols, routing, congestion control and the internet's architecture. The authors publish it free online under CC BY 4.0.
Systems ApproachIntermediate
WatchHow others solve the same problem, on video.
Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)
ReadEngineers explain it in their own words.
Blogs · Free from the author · Read here
Scalable Web Architecture and Distributed Systems
A full chapter on the building blocks of large websites: availability, performance, reliability, scalability, caches, proxies, indexes, load balancers and queues. Free to read here under CC BY 3.0.
The Architecture of Open Source ApplicationsBeginner40 min
Papers · Read here
Facebook’s photo storage
This paper describes Haystack, an object storage system optimized for Facebook’s Photos application. Facebook currently stores over 260 billion images, which translates to over 20 petabytes of data.
USENIXIntermediate
See it in another companyThe same ideas, a different system.
Case Studies · Read here
Aroma: Using ML for Code Recommendation at Facebook
Thousands of engineers write the code to create our apps, which serve billions of people worldwide. This is no trivial task—our services have grown so diverse and complex that the codebase contains…
FacebookIntermediate
Case Studies · Read here
Brooklin: Distributed Service for Near Real-Time Data Streaming at LinkedIn
Brooklin—a distributed service for streaming data in near real-time and at scale—has been running in production at LinkedIn since 2016, powering thousands of data streams and over 2 trillion messages per day. Today, w...
LinkedInIntermediate
Read the codeSee how it looks when it is real.
GitHub
Engineering Blogs
A huge directory of company engineering blogs to learn from real production systems.
kilimchoiIntermediate
GitHub
Awesome Scalability
Curated reading list of articles on the architecture of scalable, reliable systems.
binhnguyennusIntermediate
Keep learning
Loading community…