Archivestorage
Compaction Strategies: Leveled vs Tiered
Leveled compaction keeps reads fast; tiered keeps writes cheap. Every LSM engine picks a point between.
- Published
- Reading time
- 1 min read
Compaction merges SSTables to remove obsolete versions and keep read amplification bounded. The strategy determines the shape of the trade.
Leveled
Each level is sorted and non-overlapping; a key exists in at most one file per level. Reads touch one file per level (plus bloom filters), so read amp is low. Compaction rewrites large overlapping ranges, so write amp is high.
Tiered (size-tiered)
Newer runs are merged in batches of similar size. Writes are cheap because each byte is rewritten fewer times, but a key can exist in many runs, so reads probe more files and space amp grows.
Hybrids
- FIFO: time-series data with TTL; drop old files.
- Tiered+leveled (universal): tiered at the top, leveled lower down.
- Compaction-aware scheduling: throttle compaction to protect p99 read latency.
Tuning signals
Track bytes read per query, bytes written by compaction, and space amplification. If p99 reads spike after ingest bursts, leveled may be too aggressive; if writes saturate, tiered may be too loose.
Takeaway: compaction is a scheduler for three amplifications. Pick the one your SLA cannot tolerate and optimize around it.