← Lessons

quiz vs the machine

Platinum1740

System Design

Compaction Strategies

How an LSM store merges its sorted files trades read speed, write amplification, and space.

6 min read · advanced · beat Platinum to climb

Choosing How to Merge

An LSM store accumulates many sorted files and must merge them. The compaction strategy decides which files merge and when, and it directly sets the balance between read amplification, write amplification, and space amplification.

The Main Strategies

  • Size tiered groups files of similar size and merges a whole group into one larger file. Writes are cheap because data is rewritten less often, but reads may touch many overlapping files and space can spike during a merge.
  • Leveled organizes files into levels where each level holds non overlapping sorted ranges. Reads touch at most one file per level, giving tight read amplification, but each level promotion rewrites data so write amplification is higher.
  • Time windowed groups data by time, which suits time series where old windows never change and can be dropped whole.

The Three Amplifications

Every strategy is a point in a triangle of read, write, and space amplification. Improving one usually worsens another, so the right choice depends on whether the workload is read heavy, write heavy, or space constrained.

Key idea

Compaction strategies like size tiered, leveled, and time windowed each pick a point in the read write space amplification triangle, so match the strategy to whether the workload is read heavy, write heavy, or space limited.

Check yourself

Answer to earn rating on the learn ladder.

1. What does leveled compaction optimize for compared to size tiered?

2. Which strategy best fits time series data where old windows never change?

3. What triangle of tradeoffs does every compaction strategy navigate?