The write-ahead log for system design interviews, explained
A database tells a client its transaction committed, and a millisecond later the server loses power. The change was still sitting in an in-memory buffer — the data file on disk never got it — and yet when the machine reboots the change is there, intact. That is the problem a write-ahead log solves, and it is one of the most reliable ways an interviewer separates people who have read about durability from people who understand it. The core rule is a single sentence you have to be able to say and defend: write the change to an append-only log and fsync that log to disk before you touch the real data pages — log ahead of data. Get that ordering right and a crash can never lose an acknowledged write; get it wrong and "we committed" was a lie.
The reason it matters is that forcing every random data-page update to disk on every commit is far too slow, but not forcing anything means a crash loses recent writes or leaves pages half-written and corrupt. Write-ahead logging is the standard escape from that trade-off: the one thing you make durable on the commit path is a small, sequential append to a log, and the large, scattered data pages are flushed lazily in the background. This guide walks what a strong candidate names out loud: why a crash mid-write is dangerous, what a WAL is (log the change before applying it), why it is fast (sequential append vs random in-place writes), how crash recovery works (replay from the last checkpoint — redo committed, undo uncommitted), and where the same idea shows up — Postgres, SQLite, LSM-tree commit logs, and the log as a replication stream.
Why the write-ahead log comes up in system design interviews
The WAL rarely gets its own prompt. It appears inside a design — "design a database," "design a key-value store," "how does your system guarantee a write survives a crash" — the moment durability and consistency collide with performance. You say "I'll write it to disk on commit," and the follow-up is the trap: writing the actual data page is a random, expensive seek, and if you crash halfway through writing it the page is torn and corrupt — so how do you make a commit both fast and crash-safe? The WAL is a favourite probe because "I persist it to disk" is the easy half, and explaining what you persist, in what order, and how you recover is where real storage understanding shows.
The interviewer rarely lets "we just write it to disk" stand on its own. "The database says my transaction committed, then the server loses power a millisecond later. The change was still in a memory buffer, not on the data file. How did you not lose it?" That question — surviving a crash on an acknowledged write without fsync-ing the whole data file — is the one a memorised "use a WAL" answer can never survive.
The rounds on Zynter are modelled on how the loop runs, not scraped from any candidate's recall. What matters for prep is the shape: you name the WAL, and the next sentence attacks the fsync ordering, a half-applied page, or how long recovery takes after an hour of uncheckpointed writes.
What the interviewer is really testing
A WAL answer is read on the same four dimensions as any design decision. Problem solving — did you reach for a log because random page flushes are too slow and crashes tear pages, or just say "write to disk"? Communication — can you say in one sentence why the log is forced before the data, not after? Technical execution — do you explain the fsync ordering, checkpoints, and redo/undo recovery? Time management — did you spend your words on the durability-and-recovery story, not on naming a specific database? Reading this guide teaches the concept; it does not teach you to defend the fsync ordering while someone asks "what if you crash between the log write and the page write?"
The problem: a crash mid-write, and why you can't fsync every page
Start with why this is hard, because the WAL only makes sense against the alternative. A database keeps its data in fixed-size pages, cached in memory and backed by a data file on disk. A write modifies a page in the in-memory buffer. Two bad things can happen at a crash: if you have not flushed the page, the change is gone the moment power drops; if you flush it and crash mid-flush, the page is torn — half old, half new — and the file is corrupt.
The naive fix is to fsync the modified data page to disk on every commit. It is durable, but it does not scale, and you must say why:
- It is random I/O — the pages a transaction touches are scattered across the file, so each commit forces several expensive disk seeks; throughput collapses under concurrent writes.
- It causes write amplification — to durably persist a few bytes of change you flush one or more full pages (often 8KB each), over and over.
- It still risks torn pages — a single page write is not guaranteed atomic across a power loss, so even the "safe" version can corrupt a page mid-flush.
The sentence that scores: flushing the real data pages on every commit is random, seek-heavy I/O with huge write amplification, and a page flush isn't even atomic — so it's slow and unsafe. Instead you make one small, sequential, append-only thing durable on the commit path and defer the page flushes. Naming the random-I/O cost and the torn-page risk is what frames the WAL as the right answer.
What a WAL is: write the log ahead of the data
A write-ahead log is an append-only file of changes. Before a modification is applied to the data pages on disk, the database first writes a log record describing that change — enough to redo it (and often to undo it) — to the end of the log, and fsyncs the log to make it durable. Only then is the transaction considered committed and the client acknowledged. The actual data pages stay in the in-memory buffer and are flushed to the data file later, lazily, in batches. This is the whole rule, and its name is the rule: write-ahead means the log goes to disk ahead of the data.
- The commit path is cheap. The only thing forced to disk on commit is a sequential append to the log — the disk head writes contiguously, no seeks — so commits are fast even under load. Many commits' log records can be flushed in one fsync (group commit), amortising the cost further.
- The data pages are flushed lazily. The expensive random page writes happen in the background, coalesced and reordered, off the commit path. If the machine crashes before they are written, the log still has every committed change, so nothing acknowledged is lost.
The key idea to state: durability comes from the log, not the data file. At any instant the on-disk data file may be stale — missing recently committed changes — and that is fine, because the log is the source of truth for anything not yet flushed. The sentence that scores: every change is appended to a durable log before it touches the data pages; the commit only waits on a cheap sequential log fsync, and the random page writes happen lazily in the background — so a commit is fast and a crash can't lose an acknowledged write, because the log already has it.
System Design
HLD · Core concept
Explain the log-ahead-of-data ordering out loud
Crash recovery: replay from the last checkpoint
Writing the log is only half the pattern; the payoff is what happens on restart after a crash. The data file is stale and possibly missing committed changes, so the database replays the log to bring it back to a consistent state. This is where you name the two directions of recovery:
- Redo committed work. Walk the log forward and re-apply every change belonging to a transaction that committed but whose data pages may not have reached disk — this brings the acknowledged writes back. That is why the log must be durable before commit: redo can only replay what was logged.
- Undo uncommitted work. Any change belonging to a transaction that was in flight at the crash (never committed) must be rolled back, because its effects may already be sitting in flushed data pages. This redo-then-undo recovery is the ARIES intuition at a high level.
Replaying the entire log on every restart would be unbounded, so the database takes periodic checkpoints: it flushes the dirty data pages up to a point and records in the log "everything before here is safely on disk." Recovery then only has to replay from the last checkpoint, not from the beginning, which bounds restart time. Checkpoints also let the database truncate (or recycle) the old log, so it does not grow forever. The sentence that scores: on restart you replay the log from the last checkpoint — redo the committed changes that may not have been flushed, undo the uncommitted ones that may have been — and checkpoints bound how much you replay and let you truncate the log.
System Design
HLD · Core concept
Walk crash recovery and checkpoints out loud
Where the write-ahead log shows up: Postgres, SQLite, LSM-trees, and replication
The reason this concept is worth making automatic is that the same idea appears everywhere, and naming a couple of real systems is a strong signal:
- Relational databases. Postgres has an explicit WAL (its recovery and streaming replication are built on it); SQLite has a WAL journal mode; essentially every durable wal database engine logs before it writes pages. When an interviewer asks "how does your database survive a crash," this is the answer underneath.
- LSM-tree storage. Log-structured-merge stores (Cassandra, RocksDB, LevelDB) buffer writes in an in-memory memtable and would lose them on a crash — so each write first goes to a commit log, which is a write-ahead log. Same rule, different engine.
- The log as a replication / CDC stream. Because the WAL is an ordered record of every change, you can ship it to replicas and have them replay it to stay in sync — this is physical (byte-level) or logical (row-level) replication, and the same stream drives change-data-capture pipelines that feed search indexes, caches and warehouses. This is also why the WAL rhymes with a Kafka-style event log and with event sourcing: in all three, the append-only log of changes is the source of truth and the state is a replayable projection of it.
The point to state plainly: a write-ahead log is first a durability and recovery mechanism, but the same ordered log of changes doubles as a replication and CDC stream — one idea paying off twice. Being able to say "it's the same pattern as a Postgres WAL, an LSM commit log, and a Kafka event log" turns a memorised definition into understanding.
How to talk about the write-ahead log in an interview
The probes from every section rhyme. Master these five and you can defend a WAL in any storage or database design, not just this checklist.
- "What is a write-ahead log?" → An append-only file of change records that is fsynced to disk before the change is applied to the data pages, so the log — not the data file — is the source of truth for durability. (communication)
- "Why not just fsync the data page on every commit?" → It's random, seek-heavy I/O with heavy write amplification and isn't even atomic (torn pages); a sequential log append is cheap and safe, so you force the log and flush pages lazily. (problem solving)
- "You crash a millisecond after acknowledging a commit — how is it not lost?" → The commit only returned after the log record was fsynced, so recovery replays the log and redoes that committed change even though its data page never reached disk. (technical execution)
- "How does recovery actually work, and doesn't replay take forever?" → Replay from the last checkpoint — redo committed, undo uncommitted (ARIES); checkpoints bound replay time and let the old log be truncated. (technical execution)
- "Where else does this pattern show up?" → Postgres WAL, SQLite, LSM-tree commit logs, and the log shipped as a replication / CDC stream — the same append-only-log idea as a Kafka event log and event sourcing. (communication)
Each maps to a debrief dimension. Reading them teaches the answers; it does not teach you to deliver them while someone asks "what if you crash between the log fsync and the page write?" — that only comes from saying them out loud.
How to prepare: a short plan
You do not need a new topic for every design. You need the WAL vocabulary automatic, so when a design needs durability you reach for the right structure without thinking.
- Day 1: Learn the core rule — log the change and fsync it before applying it to the data pages — and why sequential appends beat random page writes, until you can draw the commit path from memory.
- Day 2: Drill crash recovery: redo committed, undo uncommitted, replay from the last checkpoint, and why checkpoints bound replay and allow log truncation. This is where the follow-ups live.
- Day 3: Place a WAL inside a real design (a key-value store, a database, a durable queue): explain the fsync ordering, recovery, and the log-as-replication-stream angle. Then do it out loud, timed, with someone asking "what if you crash mid-flush?"
This explainer feeds the broader Top 25 system design interview questions — write-ahead logging shows up in databases, key-value stores, queues and replication, so getting the pattern automatic pays off across the whole list.
Frequently asked questions
What is a write-ahead log?
A write-ahead log (WAL) is an append-only file in which a database records every change before that change is applied to its main data pages on disk. The rule is in the name: the log record is written and fsynced to durable storage ahead of the data write, and only then is the transaction treated as committed. Because the log is made durable first, it becomes the source of truth for any change that has not yet been flushed to the data file — so even if the data pages are stale or lost in a crash, the database can replay the log to recover every acknowledged write. The data pages themselves are flushed lazily in the background, off the commit path, which is what keeps commits fast.
Why is a write-ahead log faster than writing data pages directly?
Because the only thing forced to disk on the commit path is a small, sequential append to the log, whereas the real data pages a transaction modifies are scattered across the file. Writing those pages on every commit means several random disk seeks and large write amplification — you flush full pages (often 8KB each) to persist a few bytes of change. A log append, by contrast, writes contiguously to the end of a file, which is the fastest thing a disk does, and many transactions' records can be flushed in a single fsync (group commit). The expensive random page writes still happen, but lazily and in batches in the background, where they no longer slow down commits.
How does crash recovery work with a WAL?
On restart after a crash, the database replays the log to rebuild a consistent state, starting from the last checkpoint rather than the beginning. It does two things: it redoes the changes of transactions that committed but whose data pages may not have reached disk, bringing acknowledged writes back; and it undoes the changes of transactions that were still in flight at the crash, since their effects may already be sitting in flushed pages. This redo-then-undo approach is the ARIES recovery intuition. Checkpoints — where the database flushes dirty pages up to a point and records that fact in the log — bound how much of the log has to be replayed and let the older log be safely truncated so it does not grow without limit.
What is the difference between a WAL and database replication?
They are the same mechanism used for two purposes. Locally, the WAL provides durability and crash recovery. But because the WAL is an ordered record of every change the database made, you can also ship it to other machines: a replica that replays the same log ends up with the same state, which is exactly how streaming replication works (physical replication ships byte-level log records; logical replication ships row-level changes). The same stream feeds change-data-capture pipelines that keep search indexes, caches and data warehouses in sync. So "write-ahead log" and "replication log" are often the same log read by different consumers — which is also why the pattern rhymes with a Kafka-style event log and with event sourcing.
How do I practise a system design interview out loud?
Reading about the write-ahead log is not the same as defending the fsync ordering while an interviewer asks "what if you crash between the log write and the page write?" On Zynter, the HLD track runs live voice rounds modelled on how real system design loops run — you talk through a design (like a database or a key-value store) on a shared canvas, and a voice interviewer follows up one question at a time ("why not fsync every page?", "you crashed a millisecond after commit — now what?", "how long does recovery take?"), then gives you a debrief on problem solving, communication, technical execution and time management. The score is a practice signal, not a hiring decision.
Practise it on Zynter
You can say "use a write-ahead log." The round is won on the fsync ordering and the recovery story.
Pick an HLD system design round that needs durable storage, lay out the write-ahead log on the canvas, and defend it out loud to a voice interviewer that keeps asking "why not fsync every data page?" and "you acknowledged the commit, then lost power — walk me through recovery." — then read the debrief. Zynter.ai is on-demand mock interviews modelled on real company loops, with 150+ rounds across 20 companies including the HLD system design track (Sep 2026).
Practise an HLD system design round →
Browse all interview tracks




Top comments (0)