sqlite-multiwriter
github.com/sqliteai/sqlite-multiwriter- Category
- Developer Tools
- Rank
- No. 1248Tools index
Previous survey · No. 1228 ·
- Pricing
- Open Source
- Type
- TOOL
- Use case
- Data Processing
- GitHub
- 194 stars
- Latest release
- 0.6.5
- Date
About
sqlite-multiwriter enables concurrent SQLite writes across threads and processes without forking SQLite or changing the schema. Writes are faster because writers no longer queue behind SQLite's single-writer limit. In the README's benchmarks with 16 threads, throughput reached 49,277 transactions per second versus 8,630 for standard SQLite (5.7x), and tail commit latency dropped sharply.
What it does
A drop-in storage layer for SQLite that lets many connections write the same database file at once, from threads in one program or from separate programs. Each writer works on its own private copy of the pages it touches. At commit, the engine checks whether anyone else changed those pages in the meantime: if not, the commit goes through; if so, the application is told to run the transaction again. Commits land in a shared log that is folded back into the ordinary database file in the background, so the file stays readable by stock SQLite.
Why it's ranked here
It attacks the single most cited SQLite limit without forking SQLite, and it backs the claim with unusual rigor. The authors ran SQLite's own test suite through the engine: 886 of the 1,151 files that pass on stock SQLite pass identically, and the write-up explains the rest, mostly unsupported journal modes and tests that inspect files on disk. It also lists the real bugs that run found and fixed. The benchmarks are honest about where gains shrink. Against that: the numbers come from one Mac, one eight-second run each, and the isolation guarantee is described as tested rather than proved serializable.
What's good
The gains hold where most apps live: with 16 threads each inserting their own rows, 49,277 versus 8,630 transactions per second, and the slowest commit in a thousand drops from 157 ms to about 2 ms. An optional rebase mode replays row changes when two writers only collided on a shared page, so the application never sees that retry. A crashed writer process does not block the others; its unfinished work is discarded. Read validation blocks the classic write-skew anomaly, with a dedicated test for each case. The build vendors SQLite and needs nothing else, and the project ships prebuilt extensions for each platform.
Tradeoffs
Your code must wrap every write transaction in a retry loop; a conflict is reported, not waited out. When writers hit the same rows the speedup falls to roughly 2x and retries stay high. At 64 threads the median commit is slower than stock SQLite. The rebase skips tables with triggers, foreign keys, virtual tables or no rowid. Only WAL journal mode is supported, exclusive locking and auto-vacuum are refused, and a page size set on a brand-new database is ignored. Large transactions sit in memory, using two to three times their size. Multi-process mode needs a local filesystem.
How to use it well
Fits a native app, or a fleet of agents and workers, that writes one SQLite file from many places and keeps hitting busy errors. Open the database through a URI that names the extension, add the rebase flag when writers touch neighbouring rows, and add the shared mode flag for separate processes. A plain filename with the extension passed separately silently opens stock SQLite, so check that. Keep transactions small and idempotent, since they will be rerun. It does not sync databases between machines and does not help when every writer updates the same hot row.
Technical notes+
src/multiwriter_vfs.c wraps the platform default VFS and drives the per-connection lane from xShmLock: a shared read-mark lock begins a snapshot (mw_lane_on_shm_lock in src/multiwriter_tx.c), and a sqlite3_trace_v2 hook detects DDL to raise an exclusive schema barrier, exempting temp-schema changes. mw_lane_snapshot_begin registers the snapshot epoch under the registry mutex so version GC cannot reclaim visible pages, and lanes that recently conflicted take a hot-spot turn (FIFO ticket queue for long transactions, abandoned after 1 s). src/multiwriter_rebase.c replays decoded row diffs on a helper connection opened with mw_norebase=1, triggers and FKs off, gating publication after the first lost attempt (MW_REBASE_GATE_AFTER 1, MW_REBASE_MAX_ATTEMPTS 200). src/multiwriter.h exposes stats and tx identity via file-control opcodes; its comment on mw_version still reads 0.5.0 while MW_VERSION is 0.6.3. The Makefile registers the VFS through SQLITE_EXTRA_INIT and builds fault-injection variants of the log and rowdiff units.
Observed
- Language
- C, with the SQLite amalgamation vendored for builds and tests
- Interface
- SQLite VFS, loadable as a run-time extension or linked into a single library with SQLite
- Host requirement
- Loadable extension calls the host SQLite, version 3.14 or later
- Platforms
- Build targets for Linux, Linux musl, Android and Windows in the Makefile; macOS builds and fsync options documented in the README
- Concurrency modes
- Threads in one process, or multiple processes on one local file via shared memory and a segmented log
- Isolation
- Snapshot isolation with first-committer-wins at page level plus read validation; documented as tested, not proved serializable
- Unsupported SQLite settings
- journal_mode other than WAL, locking_mode=EXCLUSIVE, auto_vacuum other than none
- Compatibility testing
- SQLite's own Tcl test suite run through the engine, with per-file differences explained in docs/sqlite-test-suite.md
- Test targets
- Makefile targets for unit, multi-process, I/O fault, sanitizer and benchmark runs
Read from README.md, Makefile, docs/design.md, docs/benchmarks.md, docs/sqlite-test-suite.md, src/multiwriter.h, src/multiwriter_rebase.c, src/multiwriter_tx.c, src/multiwriter_vfs.c.
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.