Try
↑ ↓ move↵ openesc close

Interview prep / LSM trees

Senior · LSM trees · System design interview question

How does the size ratio between levels change an LSM tree, and how would you tune it?

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

A strong answer

A larger ratio makes each level bigger relative to the one above, so there are fewer levels. In leveled compaction that means fewer levels to read, and more rewriting for each entry at each merge, since each merge pulls in a larger neighbour. In tiered compaction a larger ratio means more runs wait before a merge: cheaper writes, more runs to read.

To tune, you start from the workload mix. Measure the share of writes, point reads, misses and scans, and the space budget. Then pick a policy and ratio that put the cost where the workload can bear it, and watch compaction backlog and read latency after the change.

Adaptive designs mix policies, with tiered at small levels and leveled at the largest, so that most data sits in one run and recent data is cheap to write.

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