C.W.K.
Stream
Lesson 08 of 10 · published

Litestream and Cloud-Backed SQLite

~12 min · litestream, replication, edge

Level 0Scout
0 XP0/80 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

The HA story that didn't exist before 2021

Litestream (Ben Johnson, 2021) added continuous streaming replication on top of unmodified SQLite. It tails the WAL and ships incremental changes to S3 (or sftp / GCS / Azure / file). On disaster, you restore from the latest replica with seconds of data loss.

LiteFS (also Fly.io) extended this to a clustered filesystem with synchronous writes — multi-node SQLite with strong consistency.

Turso took the libSQL fork and built a managed multi-region service. Cloudflare D1 bundles SQLite into the Workers runtime. Litesync and others fill adjacent niches.

The point: SQLite's 'no replication' objection was real for two decades and is no longer real today. For a single-region web app, Litestream alone is usually enough. For multi-region writes, Turso or LiteFS.

Tip: If you're considering RDS Postgres for cost reasons but your app fits SQLite's deployment shape, run the numbers on Litestream-on-Fly or Turso. The Pippa-shaped 'one-machine app with daily backup to cloud' setup costs single-digit dollars per month for state that would cost $50+ on managed Postgres.

Code

Litestream — install and run·bash
# macOS
brew install benbjohnson/litestream/litestream

# Or pull a binary release on Linux
curl -L https://github.com/benbjohnson/litestream/releases/download/v0.5.0/litestream-v0.5.0-linux-amd64.tar.gz | tar xz

# Replicate continuously
litestream replicate /var/lib/myapp/myapp.db s3://myapp-backups/prod/myapp

# Restore from the latest replica
litestream restore -o /var/lib/myapp/myapp.db s3://myapp-backups/prod/myapp

External links

Exercise

Set up Litestream replicating a test SQLite database to S3 (or sftp to a NAS). Insert and update rows for a few minutes. Then 'lose' the original by deleting it, restore from the replica, and confirm row counts match. Note recovery time and data-loss window.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.