Next.js Server Actions and Route Handlers let you query a database straight from your React app, so choosing that database is now a front end decision as much as a back end one. The two most common choices are PostgreSQL and SQLite. Both are excellent; the right one depends mostly on where you deploy and how much your app writes.
This guide compares them on the points that decide the choice in practice.
The short answer
- Choose SQLite if you deploy to a server or container with a persistent disk (a VPS, Fly.io with a volume, Railway, a Docker host), your app reads far more than it writes, and you want the simplest possible setup. On Vercel, use it through a hosted service such as Turso.
- Choose PostgreSQL if you deploy to Vercel or another serverless platform, expect many writes at the same time, need several services to share the database, or want PostgreSQL features such as row-level security, JSONB or full-text search.
How they differ
SQLite is a library, not a server. Your app opens a single database file and reads and writes it directly, inside the same process. There is no network, no authentication and no separate service to run.
PostgreSQL is a database server. Your app connects to it over the network, authenticates, and sends queries; the server manages many clients at once, each in its own process.
| SQLite | PostgreSQL | |
|---|---|---|
| Runs as | A library inside your app | A separate server |
| Data stored in | One file on local disk | The server's data directory |
| Concurrent writes | One at a time (readers continue in WAL mode) | Many, with row-level locking |
| Network latency | None | One round trip per query |
| Setup | None | A server or managed service |
| Shared by several apps | Not easily | Yes |
Local development
SQLite needs nothing installed. With Drizzle or Prisma you define the schema, run the migration, and the database is a file in your project. Add it to .gitignore and a new developer can clone, run npm install and start.
PostgreSQL needs a running server: a local install, a Docker container, or a free development database from a provider such as Neon or Supabase. A docker compose file with a postgres service makes this one command for the whole team.
Whichever you choose, use the same database locally as in production. SQLite and PostgreSQL differ in data types, date handling and case sensitivity, so code tested against one can fail against the other.
Deploying to Vercel
Vercel runs your server code as functions. Their file system is read-only, apart from a temporary /tmp folder that belongs to one instance and disappears when it stops. That rules out a plain SQLite file: you can read a file that was deployed with the app, but writes fail, and anything written to /tmp is not seen by other instances and is eventually lost.
There are two good options on Vercel:
- Hosted SQLite. Turso runs libSQL, a fork of SQLite, as a service. Your app connects over the network, so you keep SQLite's SQL and tooling, but it behaves like a remote database rather than a local file.
- Managed PostgreSQL. Neon, Supabase and other providers, several available through the Vercel Marketplace, give you a PostgreSQL database with a connection string and built-in pooling.
On a platform with persistent disks, such as a VPS or a Fly.io machine with a volume, a plain SQLite file works well and is the fastest option, as long as only one instance writes to it.
Connection pooling for PostgreSQL
Each PostgreSQL connection is a separate server process using memory, and the server allows a fixed number, 100 by default. A traditional app server opens a few connections and reuses them. Serverless functions are different: a traffic spike can start many instances, each opening its own connection, and the database runs out.
The fix is a pooler between your functions and the database. It keeps a small number of real connections open and shares them among many clients. Managed providers include one: Supabase and Neon both give you a separate pooled connection string, which is the one to use from serverless code. You can also run PgBouncer yourself.
Poolers in transaction mode hand a connection to a different client after each transaction, so prepared statements cannot be relied on. That is why many drivers need a setting such as prepare: false when used through one.
Setting up Drizzle with each
SQLite with a local file (Node.js runtime only, because better-sqlite3 is a native module):
import { drizzle } from "drizzle-orm/better-sqlite3";
import Database from "better-sqlite3";
const sqlite = new Database("data/app.db");
sqlite.pragma("journal_mode = WAL"); // readers no longer wait for writers
export const db = drizzle(sqlite);
PostgreSQL through a pooled connection string:
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
// prepare: false is required when the connection goes through a transaction-mode pooler
const client = postgres(process.env.DATABASE_URL!, { prepare: false });
export const db = drizzle(client);
The rest of your queries are the same apart from dialect-specific features, which is one of the reasons Drizzle and Prisma are popular for this choice.
Where SQLite fits best
- Content sites, blogs, documentation and internal tools that read much more than they write.
- Apps deployed as a single server or container with a persistent volume.
- Desktop and mobile apps, prototypes and tests, where having no database server is a real advantage.
SQLite handles a lot more than its reputation suggests. Its limit is concurrent writes: only one transaction can write at a time, so many users saving at once queue behind each other.
Where PostgreSQL fits best
- Multi-tenant SaaS, where row-level security can keep each customer's data separate.
- Apps with many simultaneous writers, such as order processing, chat or high-volume webhooks.
- Anything deployed to serverless platforms, or used by several services at once.
- Data that benefits from PostgreSQL's types and indexes: JSONB with GIN indexes, arrays, full-text search, PostGIS for location data.
Migrating later
Moving from SQLite to PostgreSQL later is possible but rarely painless: types differ (SQLite is loosely typed), dates are stored differently and any raw SQL needs checking. If you expect to need PostgreSQL within a year, start with it. If you are not sure, SQLite on a server with a persistent disk is a sound place to start, provided you keep queries in your ORM rather than in raw SQL.
Related guides
- If you write SQL by hand rather than through an ORM, read Common SQL Injection Mistakes and How to Fix Them.
- To tidy up long queries from logs or your ORM, use the SQL Formatter.
- For the rest of your Next.js performance, see the Next.js image optimisation guide.
Frequently Asked Questions
Can I use a SQLite file on Vercel?
Only for reading. Vercel functions run on a read-only file system, apart from a temporary /tmp folder that is not shared between instances and is cleared when an instance stops. Writes to a SQLite file in your project fail, and writes in /tmp are lost. For SQLite on Vercel, use a hosted SQLite service such as Turso.
Does Prisma or Drizzle work with both?
Yes. Both ORMs support SQLite and PostgreSQL with almost the same code. Features that only PostgreSQL has, such as array columns, JSONB operators, full-text search and row-level security, will not work on SQLite, so pick the database you will run in production from the start.
Do I need connection pooling with PostgreSQL on Vercel?
Yes. Serverless functions can open many connections at once during a traffic spike, and PostgreSQL allows only a limited number. Use the pooled connection string from your provider, such as Supabase, Neon or a PgBouncer you run yourself.
Is SQLite fast enough for production?
For many apps, yes. On a server with a persistent disk, SQLite runs in the same process as your app, so simple reads take microseconds with no network round trip. Its limit is writes: only one write can happen at a time, which matters for write-heavy workloads.