Exercise 1: Traditional Locking and What WAL Mode Improves — Possible Solution ==================================================================== SQLITE'S TRADITIONAL LOCKING MODEL ------------------------------ Per this chapter, "SQLite's traditional locking model (the original rollback-journal mode): at any given moment, either multiple readers can access the database simultaneously, or exactly one writer can — never both at once, and never multiple simultaneous writers. This is enforced through ordinary operating-system file locks on the database file itself." At any single moment in traditional mode, the database is in exactly one of two states: open to any number of simultaneous readers, OR locked to exactly one writer with no readers or other writers permitted at all — the two states are mutually exclusive, and which state applies is tracked using the operating system's own file-locking mechanism on the database file. THE SPECIFIC LIMITATION WAL MODE IMPROVES ON ------------------------------ Per this chapter, "a real practical consequence: in traditional mode, a write blocks all reads for its duration — a genuine limitation for any use case with meaningfully concurrent readers and writers." The specific pain point is that while a single write is happening, EVERY reader is blocked too, even though reads and writes are conceptually different kinds of operations. A read-heavy application with even one occasional writer would see all of its reads stall every time that write occurs. Per this chapter, "Write-Ahead Logging (WAL) mode is a real, meaningful improvement: readers can continue reading a consistent, slightly-older snapshot of the database while a write is in progress, since new writes are appended to a separate WAL file rather than modifying the main database file directly." WAL mode fixes exactly this specific problem — because a write is appended to a SEPARATE WAL file rather than modifying the main database file in place, readers can keep reading the still-unmodified main file (seeing a consistent, if slightly older, view of the data) at the same time a write is actively happening, rather than being blocked until it finishes. WHY THIS WORKS AS AN ANSWER ------------------------------ It explains the mutual-exclusivity of the traditional locking model precisely, names the specific limitation (writes blocking all reads) using the chapter's own wording, and explains exactly what mechanism WAL mode uses (a separate append-only file) to solve that specific problem.