Every byte, written ten times — write amplification, leveled versus tiered
Bounded levels are not free — every byte gets rewritten once per level it traverses on its way to the bottom, so a leveled LSM pays 10–30x write amplification, and the alternative (tiered) trades that down to 3–9x by accepting more files per level (worse reads, more space).
Levels capped reads — at a price. We just chose a multiplier without counting the bytes. Time to count them.
Scene 08
Every byte, written ten times
- Watch
- Try it
- Predict
- Capture
Same 1 GB ingest into both staircases. Leveled climbs to ~24× WA, tiered to ~6×. Read-amp and space-amp tell the inverse story.
Highlighted lines are the ones running in the diagram right now.
# rough WA accounting (per byte ingested):WAL_write = 1flush_to_L0 = 1L0 -> L1 = 1 # rewritten with overlapping L1 filesL1 -> L2 = 1L2 -> L3 = 1L3 -> L4 = 1L4 -> L5 = 1# total ≈ 7 in this simple model; real LSMs land at 10–30×# because a single L_i→L_{i+1} pulls in mul× overlap on the L_{i+1} side
# rough WA accounting:WAL_write = 1flush_to_L0_run = 1merge_when_K_runs = 1 # only when K runs accumulate# repeated maybe 3–4 times across the lifetime of a byte# total ≈ 3–9×# cost paid in read-amp (more files per get) and space-amp (more shadowed bytes)
Where this sits in Build an LSM-tree storage engine (LevelDB / RocksDB style)
Scene 08 of 11, in the Compaction act — Levels, write amplification, the amp triangle.. Leveled compaction pays 10–30× write amplification; tiered/universal trades that down to 3–9× at the cost of read-amp and space-amp.
Up next. We've only put records in. What about taking them out? Deletes are the next surprise — they're records too, and getting their lifetime wrong resurrects keys you thought you killed.
All 11 scenes in Build an LSM-tree storage engine (LevelDB / RocksDB style) · Every curriculum