SQLite vs Key-Value Store: Better for Web Apps?
SQLite is amazing, but managing the file in a serverless environment is a pain. Compare it with a dedicated key-value service API.
SQLite is arguably the most successful piece of software in history. It is fast, ACID-compliant, and runs everywhere. For local development, it is undefeated. But for the modern web (Serverless, Edge, Distributed), SQLite has a deployment problem.
The Data Locality Issue
SQLite is a file. db.sqlite.
To read it, your process needs direct filesystem access to that file.
- Serverless (Lambda/Vercel): The filesystem is ephemeral. You can't write to
db.sqlitebecause it disappears when the function finishes. - Docker Containers: If you scale to 5 containers, you now have 5 separate
db.sqlitefiles. They are out of sync. - The "S3 Solution": Some tools (like LiteFS) try to sync SQLite to S3. It works, but it adds significant complexity and write latency.
The Key-Value Alternative
A remote Key-Value store (like BaseKV or Redis) solves the distribution problem natively.
- Architecture: Client-Server. Your 100 Lambda functions all connect to one database.
- Protocol: TCP/HTTP. No shared filesystem required.
Performance Comparison
- Read Latency:
- SQLite (Local): Microseconds (~10µs). It's just a syscall.
- Key-Value (Remote): Milliseconds (~1-5ms). Network RTT.
- Write Throughput:
- SQLite: Limited by single-writer lock on the file.
- Key-Value: Designed for high concurrency.
When to use which?
- SQLite: Mobile apps, Electron apps, Single-server VPSS where you don't scale horizontally.
- Key-Value: Web apps running on Vercel/Netlify/AWS, distributed systems, high-concurrency APIs.
Conclusion
SQLite is great for "Local". Key-Value is great for "Distributed". If you are building a modern web app, you are likely distributed by default. Don't fight the filesystem.
Switch to a cloud-native Key-Value store. Try BaseKV.