Try
↑ ↓ move↵ openesc close

Interview prep / Indexes and filters

Mid · Indexes and filters · System design interview question

Why do LSM stores keep a Bloom filter for each sorted file, and what does it save?

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

A strong answer

A read for an absent key has to be ruled out in every file. Each check is a block read from disk. With many files, a miss costs many reads.

A small in-memory filter per file answers "definitely not here" for nearly every file that lacks the key. The read skips those files. Only the file that holds the key, and the rare file with a false positive, is read.

The filter costs memory, about ten bits per key for a rate near one in a hundred. It does not help range scans, because a filter answers membership of one key, not order. A good answer says that.

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