All the basics

What is a Bloom filter?

A tiny, quick check that says "definitely not here" or "maybe here", so you skip slow lookups for missing things.

A bouncer with a bit array: he can say 'definitely not on the list' or 'maybe', but he never wrongly turns away someone who is on it.

Press Play to watch it run · 4 steps

Bots ask for ids that do not exist. A filter in memory answers before the database does.

A filter in front of the databaseBots ask for ids that do not exist. A filter in memory answers before the database does.quick checkslow lookupBots and usersYour appBloom filterDatabase

Tap any box to see what it is and what it talks to.

  • Client
  • Service
  • Cache
  • Database
Open in playground
Text description
  1. Bots ask for thousands of ids that do not exist.
  2. Each one goes to the database to be checked.
  3. Not found, every time. The database still did the work.
  4. Real customers wait behind the pointless lookups.
  • It says definitely not, or maybe.
  • It never wrongly says no to something that is there.
  • It is tiny, because it stores bits, not the items.

Reach for it when

When most lookups find nothing, like bots guessing ids, and each database check is slow. Not when most lookups succeed.

The catch

It sometimes says maybe for ids that do not exist, wasting a lookup, and plain ones cannot delete items.

Say it in an interview“I would put a Bloom filter in front of the database: a no is certain, a maybe still gets checked, so false positives only cost one extra lookup.”