rqlite — Distributed Database Built on SQLite & Raft
Lightweight distributed relational database that replicates SQLite across nodes using the Raft consensus protocol.
What it is
rqlite turns the battle-tested SQLite engine into a fault-tolerant distributed database. Each node wraps SQLite with the Raft consensus protocol, replicating writes to a cluster of 3, 5, or 7 nodes. It serves SQL over a simple HTTP/JSON API plus a native command-line shell.
rqlite is ideal when you want relational guarantees and easy operations without the complexity of running PostgreSQL or MySQL clusters. It ships as a tiny single-binary with no external dependencies.
How it saves time or tokens
rqlite provides distributed SQL without the operational complexity of traditional database clusters. Starting a cluster takes three commands. Adding nodes requires a single join command. There is no external dependency (no ZooKeeper, no etcd). The HTTP/JSON API works with any language that can make HTTP requests, eliminating the need for database-specific drivers. Read consistency levels (none, weak, strong, linearizable) let you trade consistency for performance per request.
How to use
- Start a 3-node cluster:
rqlited -node-id 1 -http-addr localhost:4001 \
-raft-addr localhost:4002 ~/node1 &
rqlited -node-id 2 -http-addr localhost:4003 \
-raft-addr localhost:4004 -join http://localhost:4001 ~/node2 &
rqlited -node-id 3 -http-addr localhost:4005 \
-raft-addr localhost:4006 -join http://localhost:4001 ~/node3 &
- Write and read over HTTP:
curl -XPOST localhost:4001/db/execute \
-d '[["CREATE TABLE foo (id INTEGER PRIMARY KEY, name TEXT)"]]'
curl -XPOST localhost:4001/db/execute \
-d '[["INSERT INTO foo(name) VALUES(?)", "bar"]]'
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo'
- Check cluster status:
curl localhost:4001/status?pretty
Example
Using rqlite with different read consistency levels:
# No consistency check (fastest, may read stale data)
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo' \
--data-urlencode 'level=none'
# Weak consistency (confirms leader, no log check)
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo' \
--data-urlencode 'level=weak'
# Strong consistency (verifies with Raft quorum)
curl -G localhost:4001/db/query \
--data-urlencode 'q=SELECT * FROM foo' \
--data-urlencode 'level=strong'
Related on TokRepo
- Database tools — More database tools on TokRepo.
- Self-hosted tools — Browse lightweight self-hosted infrastructure.
Common pitfalls
- Running a single-node rqlite cluster in production provides no fault tolerance. Deploy at least 3 nodes for automatic leader election and failover.
- rqlite is not designed for high-throughput write workloads. Raft consensus adds latency to every write. Use it for configuration stores, metadata, and low-to-moderate write volumes.
- SQLite limitations apply: no concurrent writers per node, limited data types, no stored procedures. rqlite inherits all SQLite constraints.
Frequently Asked Questions
Raft is a consensus algorithm that ensures all nodes in a cluster agree on the same data. One node is elected leader, and writes are replicated to a majority of nodes before being committed. If the leader fails, a new leader is elected automatically.
SQLite is a single-file embedded database. rqlite wraps SQLite with Raft consensus to replicate data across multiple nodes, providing fault tolerance and a network-accessible HTTP API. rqlite adds distribution; SQLite provides the storage engine.
rqlite uses an HTTP/JSON API rather than the MySQL or PostgreSQL wire protocols. There are client libraries for Go, Python, and JavaScript that wrap the HTTP API. Standard SQL drivers for other databases will not work.
rqlite offers four read consistency levels: none (fastest, may be stale), weak (confirms current leader), strong (Raft quorum verification), and linearizable (strongest, single-value semantics). Choose per query based on your requirements.
Run an odd number of nodes (3, 5, or 7). A 3-node cluster tolerates 1 failure. A 5-node cluster tolerates 2. More nodes increase read capacity but add write latency due to Raft replication.
Citations (3)
- rqlite GitHub— rqlite distributed database on SQLite and Raft
- rqlite Docs— rqlite documentation and API reference
- Raft Paper— Raft consensus algorithm
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.