LSM-Trees vs B-Trees: Why Write-Heavy Workloads Choose Log-Structured Storage
Analyzing write amplification, SSTables, MemTables, and compaction strategies.
Table of Contents (30 Concepts)
1. Random vs Sequential Disk Writes in NVMe SSDs
Hard drives and NVMe SSDs write sequential data 10x-100x faster than random in-place page updates. B-Trees perform in-place updates leading to write amplification. LSM-trees append all writes sequentially to an in-memory MemTable and commit log.
2. B-Tree In-Place Page Splits & Write Amplification
When a B-Tree node page fills up, inserting a new key causes a 50/50 page split, requiring multiple synchronous random disk writes and WAL updates.
3. LSM-Tree Architecture: MemTable & Commit Log
LSM-Trees buffer incoming writes in an in-memory SkipList or Red-Black Tree (MemTable) while appending to a sequential write-ahead log for durability.
4. Immutable Sorted String Tables (SSTables) on Disk
When the MemTable fills, it flushes to disk as an immutable Sorted String Table (SSTable). Keys in SSTables are pre-sorted, allowing fast binary search.
5. Leveled Compaction vs Size-Tiered Compaction
Background compaction merges sorted runs to eliminate duplicate keys and reclaim disk space.
6. Bloom Filters: Eliminating Point-Lookup Disk Seeks
Probabilistic Bloom filters loaded in RAM determine whether an SSTable file contains a key with zero disk I/O for 99% of negative queries.
7. Read Amplification & Write Amplification Formulas
Calculating the exact ratio of bytes written/read to storage media versus logical bytes requested by the application.
Subscribe to continue reading the full masterclass
You’ve finished the first 7 concepts. Join 120,000+ senior engineers to unlock the remaining 23 concepts, deep-dive trade-off diagrams, and our 120+ edition archive.