Try
↑ ↓ move↵ openesc close

Interview prep / Indexes and filters

Junior · Indexes and filters · System design interview question

What is a Bloom filter, and what kinds of mistakes can it make?

Sketch your own answer first, then compare it with the one below.

A strong answer

A Bloom filter is a bit array with several hash functions. To add a key, you set the bits its hashes point to. To check a key, you test those same bits. If any is zero, the key is definitely absent. If all are set, the key is possibly present.

It makes only one kind of mistake: a false positive, where an absent key happens to land on bits that other keys have set. It never makes a false negative, because a key that was added has all its bits set.

That one-sided error is what makes it useful as a guard in front of an expensive lookup. A false positive costs one wasted lookup, never a wrong answer.

Sources

Learn it by running it

The indexes and bloom filters lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms