How data lives on disk — pages, heap files, and the two dominant storage engine models
Every database decision — index choice, write amplification, compression, compaction — traces back to how data is stored on disk. Disk I/O is the primary bottleneck in most database workloads. Understanding the storage layer explains why bulk inserts to a B-tree index are slow, why LSM-tree databases handle high write throughput better, and why sequential reads are orders of magnitude faster than random ones.
Databases don't read individual bytes — they read and write in fixed-size pages (typically 8KB or 16KB). Even reading one row loads the entire page into the buffer pool. This is why sequential access (reading pages in order) is fast and random access (jumping between pages) is slow — the disk head has to seek for each one.
Two fundamental storage models dominate: B-tree (update in place — good for reads and mixed workloads) and LSM-tree (append-only — good for write-heavy workloads). PostgreSQL and MySQL use B-trees; Cassandra, RocksDB, and LevelDB use LSM-trees.
The buffer pool hit rate is the single most important performance metric for a read-heavy database. A cold cache (restart, new query patterns) causes a surge of disk reads until pages are warmed up.
The WAL is also the foundation of point-in-time recovery — you can restore a database to any moment by replaying the WAL from a base backup up to that timestamp.