🗄️ Database Design / Normalization
Advanced
What are MVCC and write-ahead logging (WAL)?
Answer
MVCC (Multi-Version Concurrency Control) allows concurrent transactions to read a consistent snapshot of the database without taking read locks. Each row has multiple timestamped versions; readers see the version valid at their transaction start time while writers create new versions. This means readers never block writers and vice versa — critical for OLTP performance. Used by PostgreSQL, Oracle, MySQL InnoDB. WAL (Write-Ahead Log) is a durability mechanism — every change is written to a sequential log file before it is applied to data pages. On crash recovery, the RDBMS replays the WAL to restore committed transactions. WAL also enables streaming replication by shipping log records to replicas.