Databases·6 min read·

Distributed SQLite Replication with LiteFS and FUSE on Linux

Run distributed SQLite across multiple VPS nodes using LiteFS FUSE filesystem mounts for microsecond read latency and automated leader failover.

NB

Netbay Cloud Team

Netbay Engineering

On this page

SQLite is renowned for its reliability, zero-configuration setup, and blistering in-process read speeds. However, running SQLite across multiple servers has historically been constrained by network filesystem file locking limitations. LiteFS, created by Fly.io, transforms SQLite into a distributed, replicated database system. LiteFS sits as a user-space filesystem (FUSE) between your application and SQLite, capturing transaction commits directly from the Write-Ahead Log (WAL) and streaming incremental changes across secondary nodes.

For read-heavy applications, this architecture delivers microsecond local reads from High-Speed SSD storage on each node while seamlessly forwarding write transactions to the elected primary node.

How LiteFS Works Under the Hood

LiteFS runs as a background daemon managing a FUSE mount directory (typically /var/lib/litefs). When an application opens an SQLite database within this mount, LiteFS intercepts SQLite's virtual file system (VFS) system calls:

  1. **Read Transactions**: Executed locally against the local snapshot without network roundtrips. Because the data resides on local High-Speed SSD storage, reads complete in tens of microseconds.
  2. **Write Transactions**: Intercepted at the WAL boundary. If the current node is the elected primary, the transaction commits and streams LTX (LiteFS Transaction) files to replicas. If the node is a candidate or follower, LiteFS halts the write or uses its built-in HTTP proxy to forward the request to the current primary.
  3. **Lease Management**: Node coordination and leader election are managed through a lightweight distributed lease provider such as Consul or static lease configurations.

Installing and Configuring LiteFS on Ubuntu

Install the LiteFS binary and fuse3 on Ubuntu 24.04:

bash
# Install fuse3 and download the official LiteFS binary
sudo apt-get update
sudo apt-get install -y fuse3 curl

curl -fsSL -o litefs.tar.gz https://github.com/superfly/litefs/releases/download/v0.5.11/litefs-v0.5.11-linux-amd64.tar.gz
sudo tar -xzf litefs.tar.gz -C /usr/local/bin
sudo chmod +x /usr/local/bin/litefs
rm litefs.tar.gz

# Confirm installation
litefs version

Configure /etc/litefs.yml to define the mount point, data directory, and replication lease settings:

yaml
# /etc/litefs.yml
fuse:
  dir: "/var/lib/litefs"

data:
  dir: "/var/lib/litefs-data"

lease:
  type: "static"
  hostname: "node-01"
  advertise-url: "http://10.0.0.4:20202"
  candidate: true
  promote: true

proxy:
  addr: ":8080"
  target: "localhost:3000"
  db: "production.db"

exec:
  - cmd: "node /srv/app/server.js"

The proxy configuration enables LiteFS to inspect incoming HTTP requests. If a non-GET request (e.g., POST, PUT, DELETE) arrives at a replica node, LiteFS automatically transparently proxies the HTTP request to the primary node.

Expand
LiteFS Distributed Architecture
LiteFS Distributed SQLite Replication via FUSE

Managing LiteFS with Systemd

Create a systemd unit to supervise the LiteFS daemon and launch your application:

ini
# /etc/systemd/system/litefs.service
[Unit]
Description=LiteFS Distributed SQLite Replication Daemon
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/litefs mount -config /etc/litefs.yml
Restart=always
RestartSec=3s
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target

Start and verify the replication status:

bash
sudo systemctl daemon-reload
sudo systemctl enable --now litefs
sudo litefs status
LiteFS Distributed SQLite Architecture Primary Node (node-01) - App writes to /var/lib/litefs/app.db - LiteFS FUSE intercepts SQLite WAL - Generates LTX transaction frames - Commits to local High-Speed SSD - Streams delta over HTTP:20202 Replica Node (node-02) - App reads local /var/lib/litefs/app.db - Zero network hop on SELECT queries - Sub-millisecond latency - Receives LTX stream in real time - HTTP Proxy forwards POST/PUT writes FUSE-level WAL replication bridges SQLite simplicity with distributed scalability
Database Internal Architecture and Write-Ahead Logging
YouTube

Production Benchmarks and Verification

Test write forwarding and local read speed from a replica node:

bash
# Execute local read on replica (near-instant execution)
sqlite3 /var/lib/litefs/production.db "SELECT count(*) FROM users;"

# Test write forwarding via the LiteFS HTTP proxy
curl -X POST http://localhost:8080/api/users   -H "Content-Type: application/json"   -d '{"name": "Alice Developer", "email": "alice@example.com"}'

LiteFS allows you to scale SQLite across private VPS nodes, combining the zero-maintenance simplicity of embedded databases with multi-node high availability. Because reads bypass the network stack entirely, read-heavy workloads achieve microsecond latency while maintaining full transaction durability.

Deploy your distributed SQLite nodes on Netbay in under 60 seconds with High-Speed SSD storage on Lucknow DC01 — netbayhosts.in.

Keep reading

Follow along on a real VPS

Deploy Linux in under 60 seconds

These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.

Deploy an instance