Twelve Years of Distributed SQLite: Three Problems, Three Designs
SQLite is usually described as an embedded database: an application opens a file and talks to a library in its own process. There is no database server to deploy. That simplicity is powerful until the file’s machine becomes a single point of failure, a second region needs a copy, or two disconnected devices need to edit the same data. Those are three different problems. Calling every solution “distributed SQLite” can hide the choice that matters most.
Philip O’Toole’s account of twelve years of distributed SQLite begins with one of those problems. In 2014, a clustered service needed a small relational store without an obvious owner node. O’Toole put a Raft consensus log ahead of SQLite and released rqlite. The idea was to preserve a familiar SQL engine while making a group of machines agree on the order of writes. The project has continued for twelve years as other teams explored backups, embedded clusters, edge services, and offline synchronization.
The story is a useful map of the design space. It is also a reminder that SQLite itself does not magically become a multi-writer network database when its file is copied to another host. Each system has to define who may write, when a write is durable, what a reader may see, and what happens during a network partition.
The original question: can another node take over immediately?
rqlite runs as a separate server. Clients use its HTTP interface rather than opening a shared SQLite file. A Raft cluster elects one leader. A write received by a follower is forwarded to that leader; the leader orders the operation in the replicated log, waits for a majority, and applies it to SQLite. If one node in a three-voter cluster fails, the other two can still form a majority. If only one remains, writes stop. That refusal is part of the consistency guarantee, not an outage that a client can safely ignore.
The first implementation used the goraft library. O’Toole moved to HashiCorp’s Raft library in 2016, a change of consensus implementation that left the fundamental leader-and-quorum contract intact. That continuity helps explain why the project could evolve its API, snapshots, and storage handling without changing the promise applications depend on.
This buys fault tolerance and a clear write order, but not free throughput. rqlite’s FAQ says all writes pass through the leader and require network and log work; distributing the database does not scale writes beyond standalone SQLite. Batching, faster storage, and lower network latency can improve throughput. A deployment spread across distant regions pays for the extra distance on its write path.
Reads need their own policy. rqlite’s read-consistency documentation distinguishes fast local reads from leader-based and linearizable reads. A disconnected follower can answer a local read, but its result may be old. Even a leader-based weak read has a narrow leadership-change caveat; a caller requiring a linearizable result must request that level explicitly. The statement “the database is strongly consistent” is incomplete unless the application knows which read level it uses.
O’Toole describes rqlite as a consistency-first choice during partitions. That is a good fit when the application needs a self-hosted relational store, accepts a server API and one ordered writer, and needs automatic failover more than maximum write speed. It is less natural when a process must open the database directly through SQLite’s ordinary API.
The earlier work and an embedded alternative
rqlite did not emerge in a vacuum. O’Toole notes that Expensify had replicated SQLite internally with a Paxos-style approach before releasing Bedrock, while ActorDB combined actor-specific SQLite databases with Raft around the same period. His narrower historical claim is that rqlite made the Raft-plus-SQLite pattern available as a standalone, general-purpose open-source server in 2014. The distinction matters: similar needs produced similar designs, but their packaging and intended users differed.
Canonical later built dqlite for products such as LXD. It also uses Raft, but is intended to be embedded as a library. Canonical’s replication explanation describes a custom SQLite virtual file system that captures write transactions and replicates them as Raft entries. Its log, rather than an ordinary SQLite file on each node, is the persistent source of replicated state. rqlite and dqlite share a consensus goal, yet they cross different application boundaries: one is a service beside the application; the other lives inside it.
That boundary can settle an architectural decision before any benchmark. If an existing app can speak HTTP to a database service, rqlite’s packaging may be welcome. If the database needs to be part of an embedded product’s process and lifecycle, dqlite addresses a different integration problem. Both still need an operational plan for membership, upgrades, backup, and recovery.
A simpler question: can I recover after the machine dies?
Ben Johnson’s Litestream shifted attention in 2021. It continuously copies SQLite changes to object storage or another destination. The application keeps a single writable SQLite database and can restore it after losing its host. There is no Raft election and no quorum on the ordinary write path. The trade is recovery time: restoring a database and starting the application takes longer than sending traffic to an already running cluster. Replication also has a lag, so the latest local transaction may not yet exist in remote storage.
The distinction is easy to miss because both systems make data survive a failed machine. With Litestream, survival means a recoverable copy. With rqlite, it means a surviving cluster that can continue writing after a leader change, provided a majority remains. Neither property follows from the word “replication” alone. A team should set its acceptable data-loss window and recovery-time target before choosing.
Litestream’s roots in SQLite’s write-ahead log also explain why simply putting one live SQLite file on a network share is a poor substitute. WAL mode relies on shared-memory coordination among processes on one host and supports one writer at a time. Moving or streaming changes requires a system that understands the file and transaction boundaries; a blind copy of an actively changing file does not create cluster semantics.
Ideas also crossed between the projects. O’Toole credits Litestream as an influence on how rqlite version 8 handles SQLite’s WAL. These systems occupy different points in the design space, but improving the storage mechanics of one can still inform the other.
Fly.io’s LiteFS later explored another route: a file-system layer that replicates SQLite databases while applications keep local-file access. O’Toole frames it as an attempt to make replication a platform feature. Its current documentation warns that Fly.io cannot provide support or guidance for the product and calls out a data-loss risk when combined with machine autostart and autostop. That warning is a useful counterweight to the appeal of transparent replication: when leadership and freshness are hidden below the application, deployment details still matter.
A third question: can two offline writers merge?
Consensus deliberately rejects writes on a partitioned minority. Backup streaming deliberately keeps one active writer. Neither solves the local-first case in which two devices both edit data without contact and later exchange changes. cr-sqlite explores that case with a SQLite extension based on conflict-free replicated data types. Its documentation describes independently written databases that can merge when peers reconnect.
The price is a different meaning of agreement. A leader can impose one order on every transaction; disconnected peers cannot. They must carry enough change information to merge later, and an application must accept the merge semantics for its data. A counter, a last-writer-wins field, and a collaborative document may each need different rules. “Both devices may write” is useful only when the resulting state is meaningful after reconciliation. This is why local-first synchronization is not a drop-in replacement for a consensus-backed inventory ledger or payment balance.
The database became a service
The 2020s also brought projects that changed the engine or sold the surrounding service. libSQL forked SQLite to allow changes outside upstream SQLite’s contribution model; Turso built a hosted product around it. O’Toole notes that Supabase acquired Turso in 2026. SQLite Cloud sells managed replication. Cloudflare’s D1 exposes SQLite-compatible SQL through a Workers binding, while SQLite-backed Durable Objects offer another managed pattern. These products are related by storage engine, not by identical consistency or replication contracts. Their details must be checked independently.
This change in packaging is part of the twelve-year arc. rqlite, dqlite, and Litestream published infrastructure that teams could operate themselves. Hosted platforms sold provisioning, global access, operations, and an API that hides much of the machinery. A managed service can be the right choice when the operational work costs more than the bill, but “SQLite underneath” does not make it interchangeable with an embedded file or a self-hosted Raft cluster.
How to choose without confusing the guarantees
Start with the failure you need to tolerate:
- A host can fail and restoration may take minutes: use a single writer with continuous backup, then rehearse restore and measure the last recoverable transaction.
- A host can fail and writes must resume through another node: use a consensus-backed cluster, size it for a surviving majority, and test leader failover and read levels.
- Clients can write while disconnected: use a merge-aware design and specify conflict rules for each kind of data.
Then ask whether applications must open a local SQLite file, can call a separate server, or should use a managed platform API. Measure write latency across the real network, test backup and restore, and document what a read from each replica may return. The right architecture is the one whose behavior during the failure is acceptable, not the one with the broadest “distributed” label.
Twelve years after rqlite began, the durable insight is not that every SQLite database needs a cluster. SQLite’s small, reliable engine has proved flexible enough for several different systems around it. The work is choosing the contract around that engine: ordered writes, quick recovery, or independent edits that eventually merge.
Sources
- Philip O’Toole’s history of distributed SQLite
- rqlite design, FAQ, and read-consistency documentation
- Canonical’s dqlite architecture and replication documentation
- Litestream documentation
- SQLite write-ahead logging documentation
- cr-sqlite project documentation
- Fly.io LiteFS project status
- Cloudflare D1 documentation