Skip to content
Back to Deployment

Deploying with Neon

Serverless Postgres with branching, scale-to-zero, and cold-start optimization.

PlatformsIntermediate

Why

Neon separates compute and storage, allowing scale-to-zero when idle (free tier) and instant branching for preview. It's wire-compatible Postgres, so any Postgres client works.

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 Neon for serverless Postgres with branching, especially for Vercel/Cloudflare apps. Avoid for high-throughput always-on workloads (use Supabase/RDS).

How

1. Create — console.neon.tech → New Project 2. Branch — neon branches create preview (instant copy) 3. Connect — connection string, psql or any Postgres client 4. Scale — auto-suspend when idle, resume on query 5. Migrate — use psql or drizzle/prisma migrate 6. Pool — connection pooling endpoint on port 5432 7. SDK — @neondatabase/serverless for edge

Example

import { neon } from "@neondatabase/serverless"; const sql = neon(process.env.DATABASE_URL!); const users = await sql`SELECT * FROM users WHERE id = ${1}`; # Branch for preview neon branches create preview --parent main # Get connection string for branch neon connection-string preview # Drizzle config // drizzle.config.ts export default { schema: "./schema.ts", driver: "pg", dbCredentials: { connectionString: process.env.DATABASE_URL! }, };

Common Problems

  • ⚠Cold start 300ms-2s — first query after idle wakes compute, use connection pooler
  • ⚠Branch not cleaned up — preview branches accumulate, set up cleanup cron
  • ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical

Best Practices

  • ✓Use @neondatabase/serverless SDK for edge — HTTP-based, no TCP connection overhead
  • ✓Use branching for preview — instant DB copy per PR, auto-cleanup on merge
  • ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit

FAQ