Databases & Storage · core
Write-Ahead Log
Append-only durability log written before the data pages.
Mental model
The WAL is the database's promise: write the change to an append-only log and fsync it before touching the real data structure. A crash mid-write is recoverable by replaying the log. Durability before convenience.
How to study Write-Ahead Log
Begin by restating the mental model in your own words, then connect it to a concrete system you have built or operated. Name the mechanism, the constraint it addresses, and the trade-off it introduces. Use PostgreSQL — Write-Ahead Logging to check details, but close the source before writing your explanation. Retrieval is the learning step; rereading is only preparation.
Next, compare Write-Ahead Log with LSM Tree, Compaction. Ask what changes in correctness, latency, resource use, operability, and failure recovery. Complete Build a write-ahead log and preserve the command, input, output, and one failed attempt as evidence. Finish by explaining the idea without jargon to someone who has not studied the track.
Proof of understanding
- Explain the mechanism from first principles and identify the state it reads or changes.
- Give one situation where the concept is the right choice and one where it is not.
- Predict a realistic failure mode before running the drill, then compare the prediction with evidence.
- Connect the result to a roadmap or build artifact instead of treating the concept as isolated trivia.
Where it matters
PostgreSQL WAL, SQLite WAL mode, every durable store and LSM engine.
Common mistakes
- Acknowledging a write before the WAL is fsync'd
- Letting the WAL grow forever with no checkpoint/truncation
- Assuming a write() syscall means data is on disk
Learn from primary sources
Practice and explain it back
Build a write-ahead log
Implement an append-only WAL: append + fsync each change before acknowledging it, and replay the log on startup to recover state.
Expected evidence: State survives a simulated crash by replaying the log.
Open the interactive drill →Review prompts
- Why write to a WAL before updating the main data structure?
- Why is fsync required for WAL durability?
Build evidence
Toy write-ahead log
An append-only WAL with crash recovery.
- Append + fsync before acknowledging a write
- Replay the log to recover state after a crash
- Checkpoint/truncation to bound log size
Prerequisites
None assigned yet.