Guides
Deploying on Vercel and Neon
A serverless deployment with no background process: connection strings, the release step, and what to watch.
With HTTP sync (the client's default), clientdb runs entirely in Next.js route handlers, so a standard Vercel deployment with a Neon database is enough. No worker, no WebSocket server, nothing to configure in Neon.
Connection strings
| Variable | Neon URL | Used by |
|---|---|---|
DATABASE_URL | pooled (-pooler host) | the engine in route handlers |
DIRECT_URL | direct | engine.migrate() and prisma migrate deploy (Prisma's directUrl) |
Request-time locks are transaction-scoped, so the pooled URL (PgBouncer in transaction mode) works for every request. engine.migrate() takes a session advisory lock, so it uses DIRECT_URL, and refuses a pooled URL. The engine reads both variables itself:
import { createEngine } from "@clientdb/server";
import { permissions } from "./permissions";
export const engine = createEngine({
permissions,
retention: { log: "30d" }, // without it the sync log grows forever
});On Vercel the engine keeps its pool small (5 connections), since each serverless instance has its own.
The route handler
import { clientdbHandler } from "@clientdb/server/next";
import { getSession } from "@/lib/auth"; // your auth library
import { engine } from "@/sync/engine";
export const { GET, POST } = clientdbHandler(engine, {
session: async (request) => {
const session = await getSession(request);
if (!session) {
return null;
}
return { viewer: session.userId };
},
});No runtime or dynamic exports: route handlers run on Node.js by default (pg needs TCP), and Next 16 rejects both when cacheComponents is on. Don't put an edge runtime on a parent layout.
The release step
Run migrations before the new build starts serving:
{
"scripts": {
"vercel-build": "prisma migrate deploy && clientdb migrate src/sync/engine.ts && next build"
}
}clientdb migrate imports your engine module, runs engine.migrate() on DIRECT_URL, prints what it did (for example clientdb: migrated (applied nothing · rerouted todo · reconciled 3 todo)), prunes what retention no longer keeps, and closes the connection. clientdb migrate src/sync/engine.ts --dry-run prints what it would do without changing anything.
prisma migrate deploy also installs clientdb's change triggers, since they ship as a Prisma migration (npx clientdb-prisma triggers src/sync/schema.ts). migrate() adopts and reconciles rows written outside clientdb, re-routes models whose shape or rules changed, and is safe to run on every deploy.
Preview branches
Each Neon branch has its own outbox and log, so preview deployments are isolated. Clients built for another schema get SchemaOutdated and reload, so a preview and production never mix state.
What to watch
- Throughput: inline sequencing reached 1,184 tx/s across 8 instances in the benchmark. If you outgrow it, run a WebSocket server with
engine.start()elsewhere; route handlers keep working against the same log. - Log growth:
retention: { log: "30d" }keeps 30 days of the sync log; every deploy prunes the rest (with no long-running process, nothing prunes hourly). A client that last synced before the oldest kept entry loads afresh and keeps its unsent changes.engine.prune()from a cron job prunes between deploys. - Scale-to-zero: fine. Nothing holds a slot or a long-lived session.