Database / SQLite Interview questions
How does SQLite handle concurrent writes?
SQLite allows many simultaneous readers, but only ever one writer at a time for a given database file — there's no concept of row-level or table-level locking granularity the way a full client-server database offers; the whole database file is the unit of write locking.
flowchart LR
A[Multiple readers] -->|can proceed concurrently| B[Database file]
C[One writer] -->|exclusive access during write| B
D[Second writer] -->|must wait| C
In the default rollback journal mode, a writer briefly blocks new readers too during the actual commit; in WAL mode, readers can continue concurrently with the single active writer, though a second writer still has to wait its turn. This single-writer model is perfectly adequate for typical embedded, single-application use, but is the central reason SQLite isn't a good fit for applications with many independent processes all needing to write heavily and simultaneously.
More Related questions...