Litestream continuously replicates SQLite to S3, making it a production database. No PostgreSQL server needed — just SQLite with automatic backups and point-in-time recovery.
Setup
# Install
curl -sSf https://install.litestream.io | sh
# Create config
cat > /etc/litestream.yml << EOF
dbs:
- path: /data/myapp.db
replicas:
- url: s3://my-bucket/myapp
access-key-id: AKIA...
secret-access-key: secret...
EOF
Replicate Continuously
# Start replication (runs alongside your app)
litestream replicate
# Or replicate a specific database
litestream replicate /data/myapp.db s3://my-bucket/myapp
Restore from Backup
# Restore latest
litestream restore -o /data/myapp.db s3://my-bucket/myapp
# Restore to specific point in time
litestream restore -o /data/myapp.db -timestamp "2026-03-29T10:00:00Z" s3://my-bucket/myapp
Docker Integration
FROM node:20-slim
# Install Litestream
ADD https://github.com/benbjohnson/litestream/releases/download/v0.3.13/litestream-v0.3.13-linux-amd64.tar.gz /tmp/
RUN tar -C /usr/local/bin -xzf /tmp/litestream-*.tar.gz
COPY litestream.yml /etc/litestream.yml
COPY . /app
WORKDIR /app
# Restore DB on start, then run app with replication
CMD litestream restore -if-db-not-exists /data/myapp.db s3://my-bucket/myapp && litestream replicate -exec "node server.js"
Use with Your App
import Database from 'better-sqlite3';
// Just use SQLite normally — Litestream handles replication
const db = new Database('/data/myapp.db', {
// WAL mode required for Litestream
pragma: { journal_mode: 'WAL' }
});
db.exec(`CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT UNIQUE
)`);
const insert = db.prepare('INSERT INTO users (name, email) VALUES (?, ?)');
insert.run('Alice', 'alice@example.com');
Why This Matters
- No database server: SQLite is your production database
- Continuous replication: Changes replicated to S3 in seconds
- Point-in-time recovery: Restore to any second
- Simple deployment: One file database, one process for replication
- Cost: S3 storage is pennies/month vs $15+/month for managed Postgres
Need custom database backup tools or deployment automation? I build developer tools. Check out my web scraping actors on Apify or reach out at spinov001@gmail.com for custom solutions.
Top comments (0)