Skip to main content
← CONCEPTS / NOSQL & STORAGE ENGINES
An end-to-end domain learning journey

LSM-Tree Compaction Strategies: Size-Tiered
vs. Leveled vs. FIFO.

Size-Tiered Compaction minimizes write amplification (~10x) at the cost of 50% temporary disk headroom and multi-file reads, while Leveled Compaction caps space overhead at ~1.1x and bounds read amplification via non-overlapping key ranges.
Start the journey5 sections· Last modified Nov 27, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When choosing an LSM compaction strategy, match LCS to read-heavy/disk-tight KV stores, STCS to write-heavy workloads, and FIFO to TTL logs.

TL;DR30-second simplified summary
▾

STCS minimizes write amplification at ~10x but needs 50% disk headroom; LCS bounds space at 1.11x with non-overlapping key ranges; write-stalls cap L0 overlap.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
B-Tree vs. LSM-Tree
Know that LSM-Trees turn random writes into sequential MemTable flushes to immutable SSTables, which later require background compaction.
Bloom Filters
Understand how per-SSTable Bloom filters avoid disk reads for keys absent from a file.
Full walkthrough · 5 stages
01
L4 · FUNDAMENTALS

P · Problem & The Uncompacted SSTable Pileup.

Every MemTable flush creates a brand-new immutable SSTable on disk. Over a day of writes, an engine can flush hundreds of overlapping SSTables.

Without compaction, a GET(key) or range scan must merge-iterate across all 500 SSTables, and overwrites or tombstones (DELETE) never reclaim disk space. Yet running compaction greedily on every flush rewrites gigabytes of cold data repeatedly—burning out NVMe SSD endurance.

RUM Conjecture

Size-Tiered (Low Write Amp) vs. Leveled (Tight Space & Fast Reads)

Before · Size-Tiered (STCS)
  • ~10x write amplification
  • Needs ~50% free SSD headroom
  • Reads check overlapping tiers
After · Leveled (LCS)
  • ~30x write amplification
  • Only ~10% space overhead (1.1x)
  • 1 file per level (non-overlapping)
02
L4 · FUNDAMENTALS

R · Representation: Size-Tiered vs. Leveled Geometry.

In STCS, 4 small 64 MB SSTables merge into one 256 MB SSTable; 4 x 256 MB merge into 1 GB, and so on. Any key can appear in multiple tiers simultaneously.

In LCS, L0 contains freshly flushed overlapping SSTables. Once L0 reaches a threshold (e.g., 4–8 files), it merges into L1 (e.g., 10 MB total), which partitions keys into sorted, non-overlapping SSTables ([A..D], [E..H], ...). Each subsequent level L_i is 10x larger than L_{i-1} (L2 = 100 MB, L3 = 1 GB, L4 = 10 GB).

Leveled Key-Range Partitioning

Overlapping L0 -> Non-Overlapping L1 (10MB) -> L2 (100MB) -> L3 (1GB)

03
L5 · APPLIED DESIGN

I · Invariant: Write vs. Space Amplification Math.

When a 100 MB SSTable from L2 merges down into L3 (1,000 MB), it overlaps with roughly T = 10 SSTables in L3.

That means moving 100 MB down one level reads and rewrites ~1,000 MB (T = 10x write amplification per level). Across 3–4 level transitions, LCS write amplification totals ~30x–40x, whereas STCS only rewrites each byte once per tier (~10x).

LCS Compaction Step

Pick L2 SSTable -> Find Overlapping L3 Files -> Merge-Sort -> Atomic Manifest Swap

L2 SSTable (100MB)L3 Overlapping(10x)K-Way Merge +Tombstone GCMANIFEST Commit1. Select oldest L2 key range2. Read overlapping L3 SSTables3. Write new L3 files + droptombstones4. Atomic VersionEdit; unlink oldfiles
04
L5 · APPLIED DESIGN

M · Mechanics at Scale: L0 Pileups, Write Stalls & Hybrid Tiered-Leveled.

If client writes arrive faster than background compaction can drain L0 into L1, L0 accumulates dozens of overlapping files.

Once L0 hits a soft limit (e.g., 20 files), RocksDB applies smooth write-stalls (rate-limiting incoming writes) and hard-stops writes at 36 files so read latency doesn't degrade 10x.

L0 Write-Stall Guard

Normal (<12 L0) -> Soft Delay (20 L0) -> Hard Stall (36 L0) -> Recovered

L0 >= 20 filesL0 >= 36 filesL0->L1 drainsNormal WritesWrite Delay (20L0)Hard Stall (36 L0)
Engineering Decision Framework
Problem
How to pick an LSM compaction strategy that balances SSD endurance, disk headroom, and p99 read latency.
Naive Solution
Leave STCS enabled on a read-heavy or 85%-full SSD cluster.
Why It Fails
STCS runs out of disk space during major compactions (needs 50% free headroom) and suffers slow point/range reads across overlapping tiers.
Alternatives
Size-Tiered (STCS) vs. Leveled (LCS) vs. FIFO.
Engineering Decision
Default to Leveled Compaction (LCS) for balanced/read-heavy KV workloads, STCS only for write-dominated append workloads with >=50% free disk, and FIFO for pure TTL logs.
Trade-Offs
LCS trades ~3x higher SSD write amplification for 1.1x space efficiency and predictable O(L) point reads.
05
L6 · SCALE & TRADE-OFFS

E · Edge Cases, Assumptions & When NOT to Use LCS.

Deletes in an LSM-Tree write a tombstone marker—space is NOT freed until compaction reaches the bottom-most level (L_max) where the original key lives.

When NOT to use Leveled Compaction: if your workload is 95%+ blind appends/sensor logs with fixed 7-day TTL and zero updates, LCS burns 30x SSD endurance rewriting logs down 4 levels for nothing—use FIFO compaction (1.0x write amp) or time-windowed compaction (TWCS) instead!

Strategy Selection

LCS (General KV) vs. STCS (Write-Heavy) vs. FIFO (TTL Logs)

Leveled (LCS)1.1x Space / Fast ReadsSize-Tiered (STCS)Low Write Amp / 50% DiskFIFO / TWCS1.0x Amp for TTL Logs
Decision Exercise · Make the Call

A cluster running Size-Tiered Compaction (STCS) is at 72% SSD utilization with a single 800 GB Tier-3 SSTable and 3 more 800 GB SSTables about to compact. What happens when compaction triggers?

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does Leveled Compaction (LCS) with a level size ratio of `T = 10` keep space amplification near `1.11x`?

Recommended Learning Flow