Systems & Backend

Compaction

Merging and rewriting storage files in the background to reclaim space and keep reads fast — the housekeeping of LSM stores.

Compaction is the background process in log-structured storage (LSM-tree databases like Cassandra, RocksDB) that merges smaller sorted files into larger ones, discarding overwritten and deleted entries. It reclaims space and keeps reads from having to check too many files.

Worked example: writes accumulate as many small SSTables; compaction periodically merges them, dropping superseded versions and tombstoned rows, so a read consults a handful of files instead of hundreds. Gotcha: compaction competes with live traffic for disk and CPU — a poorly-timed compaction storm can spike latency — and different strategies (size-tiered vs leveled) trade write amplification against read and space amplification, a tuning decision specific to your read/write mix.