Deploying SQLite
Embedded SQL database with zero config, file-based, and litestream for replication.
PlatformsBeginner
Why
SQLite is a single-file database with no server process — zero config, ACID, and 100k+ reads/sec. With Litestream, it gets S3 replication for disaster recovery.
Platform-as-a-Service adoption grew 24% in 2024 as teams shift from VM management to git-push deploys. the cloud infrastructure market reached $330B in 2024, growing 22% year-over-year (Synergy Research), and PaaS layers capture the majority of new workloads.
When
Use SQLite for small/medium apps, edge computing, and read-heavy workloads. Avoid for high-write concurrency (single writer).
How
1. File — sqlite3 mydb.sqlite, single file
2. Schema — CREATE TABLE in SQL
3. WAL — PRAGMA journal_mode=WAL for concurrent reads
4. Litestream — litestream replicate to S3
5. Restore — litestream restore from S3
6. Backup — .backup command or copy file
7. Client — better-sqlite3 (sync) or sql.js (async)
Example
import Database from "better-sqlite3";
const db = new Database("mydb.sqlite");
db.pragma("journal_mode = WAL"); // concurrent reads
db.exec("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)");
const insert = db.prepare("INSERT INTO users (name) VALUES (?)");
insert.run("Alice");
# Litestream config — litestream.yml
dbs:
- path: mydb.sqlite
replicas:
- url: s3://mybucket/mydb.sqlite
sync-interval: 1s
# Run with litestream
litestream replicate -config litestream.yml
Common Problems
- ⚠Database locked — single writer, use WAL mode for concurrent reads
- ⚠No replication — single file, use Litestream for S3 backup
- ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical
Best Practices
- ✓Enable WAL mode — concurrent reads while writing, big perf win
- ✓Use Litestream for replication — continuous S3 backup, instant restore
- ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit