Try
↑ ↓ move↵ openesc close

Interview prep / LSM trees

Mid · LSM trees · System design interview question

How does a point read work in an LSM tree, and what makes it slow?

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

A strong answer

The read checks the memtable first, then the files from newest to oldest, and returns the first version it finds. A file is checked by looking up its index to find the one block that could hold the key.

A key that is present is usually found early. A key that is absent has to be ruled out in every file, which is the worst case. Each file check can mean a disk read.

Bloom filters fix most of this. A small in-memory filter per file says "definitely not here" for almost every file that does not hold the key. The read then touches only the file that has it, plus a rare false alarm.

Sources

Learn it by running it

The lsm trees and compaction 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