Notesstorage🌱 seedling
Write Amplification
Also: Write Amp · WA · Read Amplification · Space Amplification
The ratio of bytes a storage engine writes to disk to bytes the application asked it to write. Together with read and space amplification it forms the triangle every storage engine trades along: improving one usually worsens another.
Why it exists
Disk bandwidth and SSD endurance are finite. If each user byte becomes 30 disk bytes, the engine's real write capacity is a thirtieth of the device's.
How it works
- B-Tree: a small change rewrites a whole page, is also written to the Write-Ahead Log, and the first change after a checkpoint logs a full page image. Every Secondary Index adds its own page writes.
- LSM-Tree: each byte is written to the WAL, flushed to L0, then rewritten each time Compaction moves it down a level.
- Leveled example: 500 GB, levels 10× apart → about 1 (flush) + 2 (L0→L1) + 10 + 10 + 10 ≈ 33×, before the WAL.
- Read amplification: disk reads per query. Space amplification: bytes on disk per byte of live data.
Trade-offs
| Lower write amp by… | …and pay with |
|---|---|
| size-tiered instead of leveled compaction | more read and space amplification |
| bigger memtables, fewer levels | memory, longer recovery |
| fewer secondary indexes | slower reads for those queries |
In practice
- RocksDB works a leveled example out to about 33×, and reports write amplification per level in its compaction stats.
- High write amp is fine if background I/O keeps up; sequential LSM writes can still beat a B-tree's random page writes.
Pitfalls
- Comparing engines by a single amplification number ignores the other two.
- Indexes multiply write cost: in an engine where every index points at a physical row location, an update that moves the row rewrites every index.
Connections
- Part of
- Storage
- In real systems
- RocksDB
- Mentioned
- Write-Ahead Log
Recall
These cards are also in your review deck, scheduled with spaced repetition.