Turn a single‑file database into a fault‑tolerant backend that can survive server crashes and scale reads, all without leaving the comfort of SQLite.
Why care about SQLite replication?
Zero maintenance: no DBA required, no cluster to babysit
Tiny footprint: runs great on a $5 VPS
Transactional guarantees: WAL mode plus point‑in‑time restore
Lower cost: S3 object storage instead of multi‑node Postgres
If you have a side project or internal tool that fits on one machine, Litestream keeps it safe and highly available.
What is Litestream?
Litestream is an open‑source replication tool written in Go. It streams SQLite's WAL (Write‑Ahead Log) to cloud storage such as S3, Backblaze B2, or Azure Blob while your app is running. You get:
Continuous off‑site backups every few seconds
Point‑in‑time recovery with a single command
Read‑only replicas for scaling analytics or dashboards
Demo architecture
┌─────────────┐ WAL pages ┌────────────┐
│ VPS (app) │ ───────────────────▶│ S3 bucket│
│ FastAPI │ └────────────┘
│+ Litestream │
└─────────────┘
A FastAPI app writes to
db.sqlite3
.Litestream tails the WAL and pushes deltas to S3 every 5 seconds.
If the VPS dies, spin up a new one and run
litestream restore
to the latest commit or any timestamp.
Step 1: install Litestream
Ubuntu example:
curl -fsSL https://litestream.io/install.sh | sudo bash
Verify:
litestream version
Step 2: create an S3 bucket and IAM user
Create a bucket called
my-sqlite-backups
.Make it private; enable versioning.
Create an IAM user with
PutObject
,GetObject
, andListBucket
permissions on that bucket.Copy the access key and secret.
Step 3: add a Litestream config
/etc/litestream.yml
dbs:
- path: /home/ubuntu/app/db.sqlite3
replicas:
- url: s3://my-sqlite-backups/db
access-key-id: YOUR_KEY
secret-access-key: YOUR_SECRET
sync-interval: 5s
Step 4: run Litestream alongside your app
Systemd unit /etc/systemd/system/litestream.service
[Unit]
Description=Litestream replication service
After=network.target
[Service]
ExecStart=/usr/local/bin/litestream replicate -config /etc/litestream.yml
Restart=always
User=ubuntu
Group=ubuntu
[Install]
WantedBy=multi-user.target
Enable and start:
sudo systemctl enable --now litestream
Check logs:
journalctl -u litestream -f
You should see synced 4.2 KB to replica
.
Step 5: verify backups
List generations:
litestream snapshots -config /etc/litestream.yml
Restore locally:
litestream restore -o restored.sqlite3 -config /etc/litestream.yml
Open the file with sqlite3
and confirm your data is intact.
Scaling reads with read‑only replicas
Some workloads need heavy SELECT queries for dashboards. Launch a second VPS, restore once, and run Litestream in replica‑only mode:
litestream restore -o db.sqlite3\
-config /etc/litestream.yml\
-timestamp now
litestream replicate -config /etc/litestream.yml -exec "/usr/bin/python read_only_api.py"
Point your analytics service to this node. Writes still hit the primary; reads can scale horizontally.
Disaster recovery drill
Primary VPS explodes.
Deploy a fresh VPS with the same app code.
Install Litestream.
Run
litestream restore -o db.sqlite3 -config /etc/litestream.yml -timestamp max
.Start your application.
Downtime is the time it takes for DNS or load balancer to switch IPs plus the restore command (usually seconds).
Cost breakdown
Resource | Monthly cost |
---|---|
1 × 1 vCPU VPS | USD 5.00 |
S3 storage (5 GB) | USD 0.12 |
S3 PUT requests | USD 0.01 |
Total | ≈ 5.13 |
Cheaper than running even a single‑node managed Postgres.
Limitations
Single writer -- SQLite's write lock means only one process should write at a time.
Big blobs grow the WAL fast; consider separating object storage.
Not ideal for multi‑region write workloads.
Conclusion
Litestream upgrades humble SQLite into a resilient datastore:
Continuous off‑site backups
Point‑in‑time restore
Read replicas for cheap horizontal scaling
For many SaaS side projects and internal dashboards, this setup delivers "good enough" high availability without the complexity or cost of full‑blown clusters. Give it a spin and sleep better tonight.
Top comments (0)