Database / SQLite Interview questions
How does WAL mode improve concurrency compared to the default rollback journal?
In rollback journal mode, a writer modifies the actual database file directly (after saving the original data to a journal for potential rollback), which means readers have to wait during the brief window a writer is committing, since the file they'd be reading from is actively being changed. WAL mode instead has writers append new versions of changed pages to a separate write-ahead log file, leaving the main database file untouched during normal operation.
sequenceDiagram
participant Writer
participant WALfile as WAL file
participant DBfile as Main DB file
participant Reader
Writer->>WALfile: append new page versions
Reader->>DBfile: reads original pages (unaffected by writer)
Reader->>WALfile: also checks WAL for newer versions
Note over WALfile,DBfile: Periodic checkpoint merges WAL into main DB file
Because readers can see a consistent snapshot by combining the main database file with whatever's in the WAL at the moment they started reading, they never have to wait for a writer to finish — the writer and readers operate on effectively separate views that get reconciled later. This is the core mechanism behind WAL mode's readers-never-block-on-writers concurrency improvement.
More Related questions...