Core Concept

Write-Ahead Logging (WAL)

WAL is the ultimate baseline of system durability, allowing databases to trade slow, random disk updates for ultra-fast sequential logs.


What:

Write-Ahead Logging (WAL) is an append-only sequential log stored on disk.

Primary purpose:

Providing ACID transaction durability and crash recovery at sub-millisecond latencies.

Usually used for:

Relational databases, key-value stores (LSM-Trees), message brokers, and consensus state machines.

How should I think about this inside system architectures?

✍️ Log Intent Sequentially

Always record transaction intents to the append-only WAL first. Only update complex in-memory indexes and database pages after the log is written.

⚡ Sequential > Random I/O

Writing sequentially to disk is extremely fast, while updating random leaf pages inside B+Tree files requires slow disk heads search times.

🔄 Recoverable State

If power fails, memory is lost, but the WAL survives. Scan the log on boot to redo committed transactions and undo uncommitted updates.