Topic 3 of 5 · 4 min read
Embedded and serverless database options
Goal: Choose between SQLite, serverless PostgreSQL and a managed server for a described app and name the limit that would force a change.
An embedded database runs inside your app process and stores data in a file; a serverless database is a server you do not size or keep running. Pick either when its limit is one you will not hit, and write that limit down.
Check yourself · 1 of 3
Which workload suits SQLite best?
Why it matters
A full database server means a network hop, credentials, backups, upgrades and a bill even when idle. For a prototype, a desktop tool, a CLI, a test suite or an agent's scratch space, that is more than the job needs. The risk is the reverse: picking a file database for an app that later needs many writers on many machines.
The options
- SQLite: a complete SQL database in one file, with no server. The SQLite authors describe it as a good fit for embedded devices, application file formats, websites with modest traffic and as a stand-in for a client/server database in testing. It allows many readers but one writer at a time, and the file lives on one machine's disk.
- libSQL: a fork of SQLite that adds network access and replication, used by hosted services. You keep SQL and the file model but can serve several app instances.
- DuckDB: an embedded engine for analytical queries on local files such as CSV and Parquet. Use it to aggregate millions of rows on a laptop or in a job. It is not meant to take many small concurrent writes as an app's main store.
- Serverless PostgreSQL (for example Neon): real PostgreSQL where compute scales down when idle and starts on demand. You keep the PostgreSQL feature set and pay for a cold-start delay and a connection model that needs pooling.
- Managed server database: an always-on PostgreSQL or MySQL instance. More to pay for and size, no surprises with long-running connections and steady load.
How to choose
Ask three questions. How many processes write at once, and on how many machines? Does the data need to survive the host disk, such as a container that is replaced on deploy? Is the work transactions, or analytics over files?
Before and after
Weak: an assistant puts SQLite in a container that autoscales to 6 replicas. Each replica writes its own copy of the file, and the data is lost on redeploy. Fixed: move to a shared database (serverless or managed PostgreSQL), or keep SQLite for a single-instance app on a persistent volume with backups.
What goes wrong
- A file on ephemeral storage. The next deploy wipes it.
- Many writers on one SQLite file. Writes queue behind one writer and requests time out.
- Cold starts ignored. The first request after idle is slow and a user sees it.
- Using DuckDB as the web app's primary store. It was built for analysis, not many small concurrent writes.
Examples
Agent sandbox
A coding agent needs a scratch database to try migrations. A throwaway SQLite file in the sandbox is enough: no server, deleted with the run. A shared staging PostgreSQL would need credentials and could be damaged by the agent.
Hobby API that grew
An API runs on one VM with SQLite and 20 requests a minute. The owner adds a second VM for availability. Now two processes on two disks hold different data. The fix is a shared database; the trigger was a second machine, not traffic.
Key points
- SQLite is a strong default for single-machine apps, tests, tools and prototypes, with one writer at a time as its main limit.
- libSQL keeps the SQLite model and adds network access and replication.
- DuckDB is for analytical queries over files, not the main store of a busy app.
- Serverless PostgreSQL scales to zero and keeps PostgreSQL features, with cold starts and connection pooling as the costs.
- Name the limit that would make you move: more writers, more machines or data that must outlive the host.
Common mistakes
- Putting an embedded database on storage that disappears at redeploy.
- Scaling the app to many replicas that each have their own database file.
- Forgetting cold starts when choosing a serverless database for latency-sensitive paths.
- Treating an analytical engine as a transactional store.
Check yourself · 2 of 3
What is DuckDB mainly designed for?
Check yourself · 3 of 3
A prototype runs in a container that is replaced on every deploy. The team stores data in a SQLite file inside the container. What happens?
Practice items, not counted towards your mastery.
Start here
- Designing Data-Intensive Applications (opens in a new tab)BookPaid
The standard book on storage engines, replication and consistency trade-offs behind every database choice.
- SQLite: Appropriate uses (opens in a new tab)DocsFree
The SQLite authors list where an embedded database fits and where a client/server one is the better tool.
- MongoDB: Data modeling (opens in a new tab)DocsFree
Embedding versus referencing, and the schema design patterns for document stores.
More for this topic
- DuckDB documentation (opens in a new tab)DocsFree
An embedded columnar engine for analytical queries on local files, with its stated use cases.
- Neon documentation (opens in a new tab)DocsFree
Serverless PostgreSQL concepts: scale to zero, branching and connection handling.