advanced practice · coding problem

LSM compaction levels

L0 has 4 SSTables, threshold 4 triggers compaction to L1. Why not compact every write?

The mechanism

An LSM tree keeps producing sorted files; without compaction reads get slower and deleted data lingers. Compaction merges files, drops tombstones, and bounds read amplification — at the cost of write amplification and IO spikes.

Study Compaction

Expected evidence

Compaction is expensive; batching amortizes I/O; reads use bloom + levels.

Try this drill in the practice workspace →

Hints when you need them
  • L0 may overlap key ranges.
  • Tiered compaction trades write amp for read amp.

Watch for these mistakes

  • Ignoring the write-amplification cost of compaction
  • Not understanding leveled vs size-tiered strategies
  • Compaction storms that starve foreground traffic

Check the sources

Browse all practice briefs