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).

Previously

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

  1. Watch
  2. Try it
  3. Predict
  4. Capture
shared ingest: 100 MB/s — bytes ingested: 0 Blevel multiplier 10× — same bytes drive both staircasesleveled (low SA · low RA · high WA)L0L1L2L3L4L5write amphidden during predictread amphidden during predictspace amphidden during predicttiered (low WA · high RA · high SA)L0L1L2L3L4write amphidden during predictread amphidden during predictspace amphidden during predictSame 1 GB ingest streams into both staircases. Watch the meters tick.
What to watch for

Same 1 GB ingest into both staircases. Leveled climbs to ~24× WA, tiered to ~6×. Read-amp and space-amp tell the inverse story.

Continue unlocks when the animation finishes.
Implementation

Highlighted lines are the ones running in the diagram right now.

WA on a leveled LSM
every byte rewritten once per level transition
# rough WA accounting (per byte ingested):
WAL_write = 1
flush_to_L0 = 1
L0 -> L1 = 1 # rewritten with overlapping L1 files
L1 -> L2 = 1
L2 -> L3 = 1
L3 -> L4 = 1
L4 -> 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
WA on a tiered LSM
merges happen RARELY — multiple runs sit in each level
# rough WA accounting:
WAL_write = 1
flush_to_L0_run = 1
merge_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

Built with Arqly
Every scene in Build an LSM-tree storage engine (LevelDB / RocksDB style) builds on the one before it.All 11 Build an LSM-tree storage engine (LevelDB / RocksDB style) scenes