This is a great question about the trade-offs between B-trees and LSM-trees (Log-Structured Merge-trees), specifically focusing on write amplification (WA). Let me break this down comprehensively.
Write Amplification Definition
Write amplification is the ratio of actual bytes written to storage versus logical bytes written by the application. Higher WA means more total I/O overhead.
B-tree Write Amplification
Why B-trees have high WA:
-
Random Page Updates: When you update a key-value pair in a B-tree:
- The page containing that key is read from disk
- The entry is updated
- The entire page (usually 4KB) is written back to disk
- If the key doesn't fit (page overflow), pages may split, cascading writes up the tree
-
Example:
- Application writes 100 bytes
- System must read/write a full 4KB page
- WA ~ 4KB/100B = 40x
-
Multiple Disk Operations:
- Read page (if not in cache)
- Write page
- Potentially write leaf node, parent nodes due to splits
- Write to WAL (Write-Ahead Log) for durability
-
Random I/O Pattern:
- SSDs and especially HDDs perform poorly with random access
- Each update might touch different pages scattered across disk
LSM-tree Write Amplification
Initial write path (low WA):
- Write to memtable (in-memory buffer) - very fast
- Write to WAL (sequential, linear growth) - fast
- WA for initial write is very low, maybe 1-3x
But compaction adds complexity:
-
Compaction Process:
- When memtable fills, it's flushed to disk as immutable SSTable (Sorted String Table)
- Multiple SSTables need to be merged (compaction)
- During merging, data gets re-read and re-written, deferring the true cost of writes
-
Total WA Calculation:
- A single byte written initially may traverse multiple levels before settling
- With K levels, WA scales roughly as O(K), depending on how data flows through the structure
- Leveled compaction (where each level is typically 10x larger) produces WA around O(L * log N), where L is the amplification factor
-
Compaction Strategy Trade-offs:
- Leveled approaches minimize read amplification but increase write overhead
- Tiered strategies reduce write costs at the expense of more reads during merging
- Hybrid approaches attempt to balance these competing concerns
Despite this overhead, LSM-trees excel for write-heavy scenarios. Sequential writes to storage are far more efficient than random ones—SSDs and HDDs both achieve higher throughput with sequential I/O patterns. LSM naturally batches writes sequentially, whereas B-trees scatter updates randomly across the structure. Additionally, compaction work happens asynchronously rather than blocking writes, allowing the system to sustain high write throughput even as background merging occurs.
B-tree write amplification is immediate and per-operation, while LSM defers and amortizes this cost over time. For sustained write workloads, this deferral is advantageous. LSM also maintains better cache locality by keeping hot data in the memtable, whereas B-tree random updates can cause cache thrashing. Tail latency remains more predictable with LSM since memtable writes are consistent and compaction can be scheduled during idle periods.
Looking at concrete numbers, a B-tree handling random 100-byte writes on 4KB pages with split overhead incurs roughly 80-100x write amplification immediately. An LSM with leveled compaction across three levels accumulates similar total amplification (around 111x), but the critical distinction emerges under sustained load: B-tree forces this amplification on every operation, while LSM spreads it across background compactions that can be deferred or throttled. This means LSM achieves better effective throughput for write-heavy workloads despite comparable theoretical amplification ratios. During idle periods, compaction overhead gets absorbed, allowing effective throughput to reach 300M keys/sec or higher. The key distinction is that LSM defers write amplification costs while B-trees pay them immediately on each write. For write-heavy workloads, this deferral matters because compaction can overlap with read operations, batch multiple writes together, and leverage sequential I/O patterns that modern devices handle efficiently. That said, LSM isn't universally superior—point reads require checking multiple levels and range queries can suffer, plus compaction itself introduces unpredictable latency spikes.
B-tree vs LSM-tree Write Amplification Analysis
The Core Trade-off
You've identified the paradox perfectly: LSM's total write amplification can rival B-trees, yet LSM dominates write-heavy workloads. Here's why the distinction matters:
| Metric | B-tree | LSM |
|---|
| WA per write | Immediate | Low (initial) |
| WA timing | Synchronous | Deferred (async) |
| I/O pattern | Random | Sequential |
| Device utilization | Poor match | Excellent match |
B-tree Write Amplification (Synchronous)
Why it's high:
Application Writes 1KB
↓
[Read 4KB page from disk] ← Unless cached, this is a stall
↓
[Update 1KB entry in page]
↓
[Write back 4KB page]
↓
[Cascade: Page split? Write parent nodes]
↓
[Write to WAL for durability]
────────────────────────────
Total: 40KB written for 1KB logical write = 40x WA
But device capacity is 100 MB/s (random).
Effective throughput: 100 / 40 ≈ 2.5 MB/s application data
The killer: This happens on the critical path — every write blocks until the page persists.
LSM Write Amplification (Deferred via Compaction)
Initial write path (optimized):
Application writes 1KB
↓
[Add to memtable in RAM] ← O(1) append
↓
[Write 1KB to WAL sequentially] ← ~1x WA, super fast
────────────────────────────
Total: 1-2x WA, microseconds
Device isn't even saturated; we achieved 100,000x parallelism
Compaction adds the deferred cost:
Level 0 SSTable (100MB) → Level 1 SSTable (1GB)
│
├─ Read 100MB sequentially
├─ Merge-sort with existing L1 data
└─ Write 1GB sequentially
Total compaction WA = 10x per level transition
If K levels: Total accumulated WA ≈ O(10^K) across all data lifetime
But: This happens in BACKGROUND, not on write path
Why LSM Wins for Write-Heavy Despite Higher Total WA
1. Device Physics Dominate
Same device, same total data written, different outcomes:
B-tree (random):
- Device max: 100 MB/s
- WA: 40x
- Effective throughput: 100 / 40 = 2.5 MB/s
LSM (sequential):
- Device max: 300-400 MB/s (3-4x faster)
- WA: ~50x (higher total, but over longer amortization window)
- Effective throughput: 350 / 50 = 7 MB/s (2.8x faster!)
Sequential beats random by such a large margin that even higher total WA is forgiven.
2. Write Synchronicity Matters
B-tree: 40x WA @ 100 μs per operation
= 40KB written in 4 ms per 1KB write
→ STALLS APPLICATION
LSM: 2x WA @ 1 μs per operation
+ 50x WA @ 10 ms (background compaction, not blocking writes)
→ APPLICATION PROCEEDS UNBLOCKED
Compaction WA is paid asynchronously. You can:
- Compact during idle periods
- Run compaction on separate threads/cores
- Throttle based on read performance needs
3. Batching Efficiency
B-tree:
Write A (random page 10000) ← Seek cost
Write B (random page 50000) ← Seek cost
Write C (random page 20000) ← Seek cost
→ Cannot batch efficiently
LSM Memtable (before compaction):
Write A ──┐
Write B ├─→ [Sequential sorted batch]
Write C ──┘
→ All three absorbed without device thrashing
Quantifying the Deferred Advantage
Model: Write-heavy workload (100K writes/sec, 1KB each)
B-tree scenario:
100K writes/sec × 40x WA = 4,000 MB/sec device traffic (PEAK)
Device capacity: 100 MB/sec random
Result: QUEUE BUILDS ❌ → Blocked writes, high latency
LSM scenario:
Memtable writes: 100K writes/sec × 2x WA = 200 MB/sec (easily absorbed)
Device capacity: 300 MB/sec sequential
Compaction traffic: Scheduled in background, smoothed over time
Result: Sustainable throughput ✓ → Predictable latencies
The Hidden Assumption
LSM's advantage assumes compaction doesn't interfere with reads:
Good (LSM shines):
├─ Write-heavy, read-light
├─ Can schedule compaction during off-peak
├─ Separate I/O channels for compaction
└─ SSD with good read/write parallelism
Problematic (LSM stumbles):
├─ Read-heavy + concurrent writes
├─ Single spinning disk (seeks during compaction hurt reads)
├─ Compaction spikes cause read tail latency
└─ Memory-constrained (compaction must be aggressive)
Practical System Examples
| System | Why LSM? |
|---|
| RocksDB | 100x+ throughput vs B-tree at similar latency |
| Cassandra | Sustains millions writes/sec TSDBs demand |
| LevelDB | Designed for SSD sequential strength |
| PostgreSQL (B-tree) | Stays competitive on:mixed workloads, point reads, range queries |
The Bottom Line
LSM doesn't truly have lower write amplification—it has better amortization of write amplification:
- B-tree: Pay WA proportionally to each write latency cost
- LSM: Defer WA to background, get temporary throughput boost
For write-heavy workloads, this temporal deferral is worth far more than the total WA count because:
- Device I/O ceiling is higher (sequential >> random)
- Asynchronous compaction doesn't block writers
- Batching effects reduce effective WA during peak loads
The trade-off: Read latency spikes during compaction, need careful compaction tuning, and higher peak I/O.