Architectural Breakdown & AnalysisFAANG Aligned
Databases store records differently on disk based on whether their workload is write-heavy or read-heavy.
B-Tree (Read-Optimized: PostgreSQL, MySQL)
- Organizes data in self-balancing multi-way trees on disk.
- Updates pages in-place via random disk I/O.
- Pros: Lightning-fast point lookups ($O(\log N)$) and range queries.
- Cons: High write amplification due to page rewrites.
LSM-Tree (Write-Optimized: Cassandra, RocksDB)
- Appends all writes sequentially to an in-memory buffer (MemTable) and Write-Ahead Log (WAL).
- Flushes MemTable periodically to immutable sorted disk files (SSTables). Background threads compact duplicate keys.
- Pros: Ultra-fast write speeds via sequential disk appends.
- Cons: Read path requires searching multiple SSTables using Bloom Filters.
TIP — Storage Selection
Choose B-Trees for transactional read-heavy OLTP workloads. Choose LSM-Trees for high-ingestion logging, telemetry, and time-series systems.
Key Architectural Comparison
| Storage Engine | Write Strategy | Read Strategy | Random I/O Impact | Best Fit Workload |
|---|---|---|---|---|
| B-Tree | In-place overwrite of disk pages. | Direct $O(\log N)$ point lookups. | High random write I/O. | Read-heavy OLTP databases (PostgreSQL, MySQL). |
| LSM-Tree | Sequential append to MemTable + Commit Log. | Multi-SSTable scan filtered by Bloom Filters. | Zero random write I/O (pure sequential disk writes). | High-ingestion write workloads (Cassandra, RocksDB). |