Next.js + PostgreSQL

IntermediateWeb App

Next.js with a PostgreSQL database, an ORM, and authentication: full-stack TypeScript web apps.

Published 27 September 2026

Core Tools
Next.js
Next.js
React
React
TypeScript
TypeScript
Database
PostgreSQL
Neon
Prisma Postgres
PlanetScale
ORM
Prisma ORM
Drizzle
TypeORM
Authentication
Clerk
BetterAuth
Auth0
Hosting
Vercel
Netlify
Railway
Render
Firebase Hosting
+3

About Next.js + PostgreSQL

Next.js + PostgreSQL is the dominant full-stack TypeScript stack for teams that want the flexibility of a custom database schema without the black-box of a BaaS platform. Next.js App Router lets React Server Components query PostgreSQL directly on the server, eliminating the need for a separate API layer for most data fetches. Server Actions handle form mutations and data writes with typed function calls instead of hand-written REST endpoints. Authentication comes from a managed provider (Clerk or Auth0) or a self-hosted library like BetterAuth, if you'd rather not depend on a third-party identity service for user data.

PostgreSQL brings full relational power: complex JOINs, CTEs, window functions, JSONB columns, and full-text search: queries that document databases struggle with and that generic BaaS platforms abstract away. You access it via Prisma or Drizzle, depending on how much schema-first tooling you want over a leaner SQL-like API, or TypeORM if the codebase already uses its decorator style. The database itself can be self-managed on your own server, or a managed serverless option like Neon, Prisma Postgres, or PlanetScale if you'd rather not run Postgres yourself.

Next.js deploys to a serverless platform, a container PaaS, or a self-hosted VPS; the serverless platforms add edge middleware for auth guards, A/B testing, and redirects at the CDN layer. Incremental Static Regeneration (ISR) lets you serve near-static pages that revalidate in the background. This stack scales from a side project to a funded company without architectural rewrites: the same patterns that work for an MVP work at meaningful scale.

Key Features

  • ✓React Server Components query PostgreSQL directly on the server, with no separate API layer
  • ✓Server Actions handle form mutations without writing API endpoints
  • ✓Type-safe database access: use Prisma, Drizzle, or raw SQL with postgres.js
  • ✓Next.js App Router with layouts, loading states, and nested error boundaries
  • ✓PostgreSQL with full SQL power: CTEs, window functions, JSONB, full-text search
  • ✓Incremental Static Regeneration (ISR) for near-static pages with fresh data
  • ✓Edge middleware for auth guards, A/B testing, and redirects at the CDN layer

When to Use Next.js + PostgreSQL

  • →SaaS applications with complex data relationships and multi-tenancy
  • →Content-heavy sites that need SEO with dynamic data
  • →B2B tools and internal dashboards
  • →Marketplace and e-commerce platforms
  • →Developer-facing products and documentation sites
  • →Multi-step onboarding and form-heavy applications

Pros

  • End-to-end TypeScript from PostgreSQL schema to React component, so type errors surface early
  • React Server Components reduce client-side JavaScript and improve Time to First Byte
  • PostgreSQL handles complex queries that document databases struggle with

Cons

  • Next.js App Router caching is complex: cache invalidation requires understanding multiple layers
  • Server Actions are still maturing, with some edge cases around error handling and revalidation
  • Serverless function pricing on Vercel-style platforms can become significant at scale, a reason to consider self-hosting
  • Cold start latency on serverless deployments can affect time-sensitive routes

Database Options for Next.js + PostgreSQL

PostgreSQL

Next.js + PostgreSQL with self-hosted PostgreSQL

The standard choice: a full PostgreSQL instance on a managed host or your own server, with complete control over configuration and extensions.

Neon

Next.js + PostgreSQL with Neon

Serverless PostgreSQL that scales to zero when idle and branches like Git. A strong fit for Vercel deployments and preview environments, with no server to manage.

Prisma Postgres

Next.js + PostgreSQL with Prisma Postgres

Serverless PostgreSQL from the Prisma team, billed per operation and integrated with the Prisma ORM. Convenient when your Next.js app already uses Prisma.

PlanetScale

Next.js + PostgreSQL with PlanetScale

A serverless database platform built on Vitess, with schema branching and deploy requests that turn risky schema changes into a reviewable pull-request-style workflow. Originally MySQL-only; now also offers a serverless PostgreSQL engine, so it fits here as a Postgres backend with that branching workflow on top.

These are highlighted picks. To see all the tools, check the Databases category.

ORM Options for Next.js + PostgreSQL

Prisma ORM

Next.js + PostgreSQL with Prisma ORM

Schema-first ORM with a fully type-safe client and auto-generated migrations. The most common data layer for a Next.js app on PostgreSQL.

Drizzle

Next.js + PostgreSQL with Drizzle

SQL-first, lightweight ORM with full type inference. A leaner alternative that reads like SQL and suits edge and serverless deployments.

TypeORM

Next.js + PostgreSQL with TypeORM

A mature ORM with a choice between Active Record and Data Mapper patterns and heavy use of TypeScript decorators for defining entities. Worth reaching for mainly if the codebase already uses TypeORM's decorator style from an existing NestJS backend. For a new project on PostgreSQL alone, Prisma or Drizzle cover the same ground with less setup.

These are highlighted picks. To see all the tools, check the ORMs & Query Builders category.

Authentication Options for Next.js + PostgreSQL

Clerk

Next.js + PostgreSQL with Clerk

A fully managed auth service with prebuilt sign-in/sign-up UI components, session management, and social logins ready out of the box. It's the fastest path to production auth, priced per monthly active user past a free tier.

BetterAuth

Next.js + PostgreSQL with BetterAuth

A self-hosted, open-source auth library you own and run yourself, so no vendor account holds your users' data and there's no per-user pricing, at the cost of building and maintaining the sign-in flow yourself. The former nextjs-better-auth stack was built entirely around this tradeoff; it's now available here as an authentication choice instead of a separate stack.

Auth0

Next.js + PostgreSQL with Auth0

An enterprise-oriented managed auth platform with extensive protocol support (SAML, enterprise SSO) and fine-grained access control. Typically the pick when the app needs compliance or enterprise-customer auth features Clerk doesn't cover.

These are highlighted picks. To see all the tools, check the Authentication category.

Hosting Options for Next.js + PostgreSQL

Vercel

Deploy Next.js + PostgreSQL on Vercel

The platform Next.js's own team builds for, with zero-config deploys straight from a git push and edge/serverless functions handled for you, backed by Vercel's global edge network for CDN delivery. Free Hobby usage is scoped to personal, non-commercial projects under Vercel's terms; production or client work needs the Pro plan, around $20/mo per seat, with usage-based charges for bandwidth and function execution beyond the included allowance. Every push to the main branch redeploys automatically, so a CI/CD addition mainly earns its place running a test suite that gates the deploy.

Netlify

Deploy Next.js + PostgreSQL on Netlify

A comparable git-based deploy platform to Vercel, with strong SSR/static build support, a mature build-plugin ecosystem, and its own global CDN. The free tier covers a personal or small project; paid plans start at $9/mo (Personal), with Pro at $20/mo once traffic or build usage grows. Like Vercel, it redeploys automatically on push, so a CI/CD addition adds the most value running tests before that deploy goes out rather than triggering it.

Railway

Deploy Next.js + PostgreSQL on Railway

A container-based platform where the app deploys as a persistent service instead of a set of serverless functions, useful for long-running processes, WebSocket connections, or background jobs a serverless model doesn't fit well. There's no free tier: the Hobby plan starts around $5/mo in usage credit, plus further usage-based billing for CPU, memory, and network. It auto-deploys from a connected repo on push, and since it has no CDN of its own, pairing it with a separate CDN mainly matters if static asset delivery becomes a bottleneck.

Render

Deploy Next.js + PostgreSQL on Render

A similar persistent-service model to Railway, with built-in cron jobs, a genuinely free tier for small services, and its own CDN for any static assets. Free-tier web services spin down after inactivity and take a few seconds to restart on the next request; predictable always-on pricing starts around $7/mo, a straightforward alternative if that matters more than usage-based serverless billing. Deploys automatically on push the same way Railway does, so CI/CD's value here is pre-deploy testing, not the deploy itself.

Firebase Hosting

Deploy Next.js + PostgreSQL on Firebase Hosting

Google's static hosting layer, typically paired with Cloud Functions for any server-rendered routes, delivered over Google's global CDN. The free Spark plan (10GB storage, roughly 360MB of daily transfer) covers light usage; the Blaze plan bills by actual usage beyond that. It lacks Vercel/Netlify's all-in-one framework adapters, so setup takes more manual configuration, and deploys go through the Firebase CLI rather than an automatic git-push pipeline by default.

Hetzner

Deploy Next.js + PostgreSQL on Hetzner

A self-hosted VPS with full control over the server and its costs, at the price of managing deployment, scaling, and updates yourself instead of a managed platform handling them. Entry-level instances start around €4-5/mo, by far the cheapest option in this list, though there's no bundled CDN, so serving a global audience typically means pairing it with a separate CDN like Cloudflare in front. Nothing deploys automatically here by default; a CI/CD pipeline, or at least a deploy script it triggers, is genuinely how code gets from the repo onto the server.

Fly.io

Deploy Next.js + PostgreSQL on Fly.io

Runs the app as a container close to users across multiple regions, a middle ground between a fully managed serverless platform and a fully manual VPS like Hetzner. Billing is usage-based with only a small free allowance, so cost scales with actual compute and bandwidth rather than a flat monthly fee; it also has no dedicated static-asset CDN, since its edge model is about running compute near users rather than caching files. Deploys go through the flyctl CLI or a CI/CD pipeline rather than an automatic git-push webhook by default.

DigitalOcean

Deploy Next.js + PostgreSQL on DigitalOcean

A managed VPS or App Platform deployment with predictable flat-rate pricing, starting around $4-6/mo for a basic Droplet or about $5/mo for App Platform's smallest tier, which also includes a free static-site option. Neither includes a CDN by default, though DigitalOcean sells one (Spaces CDN) as a separate add-on if needed. The App Platform tier auto-deploys from git similarly to Vercel/Netlify; a bare Droplet behaves like Hetzner, where a CI/CD pipeline is how the deploy actually happens.

These are highlighted picks. To see all the tools, check the Hosting & Cloud category.

Next.js + PostgreSQL Add-ons

Each addition below extends this stack with a capability the base stack works fine without. None are required: include the ones your product actually needs when building this stack, and skip the rest.

CI/CD Add-ons

Add CI/CD when you want a dedicated pipeline for running tests, linting, or multi-stage builds before a deploy goes out. Many hosting platforms already redeploy automatically on every push on their own — a CI/CD tool adds the most value on top of that by gating the deploy on a passing test suite, and matters even more when the hosting choice does not auto-deploy at all, such as a self-hosted server.

GitHub Actions

Next.js + PostgreSQL with GitHub Actions

Runs the test suite and triggers deployments on every push, directly from the same GitHub repo the code already lives in, with no separate CI service to configure.

GitLab CI/CD

Next.js + PostgreSQL with GitLab CI/CD

GitLab's built-in CI/CD system, configured via .gitlab-ci.yml in the repository, the natural pick if the project's code lives on GitLab (self-hosted or gitlab.com) rather than GitHub, with the same YAML-pipeline model as GitHub Actions.

These are highlighted picks. To see all the tools, check the CI/CD Pipelines category.

Containerization Add-ons

Add containerization when you want the app packaged the same way across local development, staging, and production, or need to deploy somewhere that isn't a managed serverless platform.

Docker

Next.js + PostgreSQL with Docker

Packages the app and its dependencies into a container image for consistent local development and deployment, independent of the hosting platform chosen above.

These are highlighted picks. To see all the tools, check the Containerization category.

Observability Add-ons

Add observability when you want to catch errors and performance regressions in production before users have to report them.

Sentry

Next.js + PostgreSQL with Sentry

Error tracking and performance monitoring with a dedicated @sentry/nextjs SDK: automatic error boundaries, stack traces with source maps, and request tracing across both server and client code. Open-source with a self-hosted path, alongside its own managed cloud.

Datadog

Next.js + PostgreSQL with Datadog

A broader observability platform covering APM, infrastructure metrics, and log management in one dashboard, useful once a team is already running other services worth monitoring alongside the Next.js app. Managed-only, with pricing that scales by host and usage rather than Sentry's per-error volume.

These are highlighted picks. To see all the tools, check the Infrastructure & APM category.

Email Add-ons

Add email when the app needs to send account verification, password reset, or notification messages.

Resend

Next.js + PostgreSQL with Resend

A transactional email API for account verification, password resets, and notification emails, the kind of email a SaaS app sends on behalf of the system rather than a marketing campaign. Drops into Next.js Server Actions or Route Handlers with a few lines of code, with a free tier for getting started.

SendGrid

Next.js + PostgreSQL with SendGrid

The established high-volume choice, with dedicated IP addresses and deliverability tooling for apps sending at serious scale. There is no permanent free plan (a 60-day trial, then paid tiers), so it earns its slot when volume and deliverability matter more than upfront cost.

Brevo

Next.js + PostgreSQL with Brevo

An all-in-one platform that combines the transactional email API with marketing campaigns, a built-in CRM, and SMS from the same dashboard. Its permanent free tier of 300 emails a day with no card required makes it an easy starting pick for early-stage apps that will also want lightweight marketing sends.

Payments Add-ons

Add payments when the product is ready to charge for subscriptions or one-time purchases.

Stripe

Next.js + PostgreSQL with Stripe

Adds subscription billing, one-time checkout, and invoicing via Stripe's hosted Checkout or embedded Elements. The stack works fully without it; add this once the product is ready to charge for something.

Styling Add-ons

Add styling when you want a component or utility-class system to build the UI faster than hand-writing CSS from scratch.

Tailwind CSS

Next.js + PostgreSQL with Tailwind CSS

A utility-class CSS framework: styles are composed directly in markup via class names instead of writing separate stylesheet files. The default styling choice for new Next.js projects (create-next-app includes it as an option), and the base layer shadcn/ui components are built on when that's loaded in the future.

These are highlighted picks. To see all the tools, check the CSS Frameworks category.

Analytics Add-ons

Add analytics when you want to measure traffic, track visitor behavior, or understand how people actually use the product.

PostHog

Next.js + PostgreSQL with PostHog

An all-in-one product analytics platform: event tracking, session replay, feature flags, and A/B testing in one SDK. The richest feature set if you want more than pageviews.

Google Analytics

Next.js + PostgreSQL with Google Analytics

The industry-standard, free analytics platform, with native Google Ads and Search Console integration. Requires a cookie consent banner in most jurisdictions (GDPR/CCPA), and all data lives on Google's infrastructure, the tradeoff the other three picks were built to avoid.

Plausible Analytics

Next.js + PostgreSQL with Plausible Analytics

A lightweight, privacy-first analytics tool with no cookie banner required. A good fit for simple traffic metrics without PostHog's broader feature surface.

Umami

Next.js + PostgreSQL with Umami

Open-source and self-hostable, keeping analytics data on infrastructure you control. Pairs naturally with the self-hosted Hetzner hosting option above if you want to avoid a third-party analytics vendor entirely.

These are highlighted picks. To see all the tools, check the Web & Product Analytics category.

Frequently Asked Questions about Next.js + PostgreSQL

Which ORM should I choose: Prisma, Drizzle, or TypeORM?

Prisma is the default for most teams: schema-first, fully typed, with auto-generated migrations and the largest ecosystem. Drizzle is worth it if you'd rather write SQL-like queries directly and want a lighter runtime, especially on edge or serverless deployments where Prisma's engine adds overhead. TypeORM mainly makes sense if the codebase already uses it from an existing NestJS backend, or if you specifically want its decorator-based Active Record style. For a new project on PostgreSQL alone, Prisma or Drizzle cover the same ground with less setup.

Should I use Clerk, BetterAuth, or Auth0 for authentication?

Clerk gets you to production fastest, with prebuilt sign-in UI and session handling out of the box, and is the right default unless its per-user pricing becomes a concern at scale. BetterAuth is the pick if you'd rather own the auth flow yourself and avoid a per-user cost entirely, at the cost of building the UI and session logic yourself. Auth0 is worth the extra setup only if the app needs enterprise features like SAML or SSO that Clerk doesn't cover.

Do I need a separate backend API, or can Next.js talk to PostgreSQL directly?

For most of this stack, no separate API layer is needed: React Server Components query PostgreSQL directly on the server, and Server Actions handle writes as typed function calls instead of hand-written REST endpoints. A dedicated API only becomes necessary if another client, like a mobile app or a third-party integration, needs to call the same data outside of Next.js itself.

Can I switch from self-hosted PostgreSQL to Neon or Prisma Postgres later without a rewrite?

The database option only changes where PostgreSQL runs, not how you talk to it. Since the ORM (Prisma or Drizzle) is the layer that touches your code, switching from a self-hosted instance to Neon or Prisma Postgres is a connection-string change, not a schema or query rewrite, as long as you're not relying on Postgres extensions the serverless option doesn't support.

What's the cheapest way to run this stack?

Self-hosted PostgreSQL, BetterAuth, and Vercel or Netlify's free tier cost nothing beyond wherever you host Postgres itself. The first real cost most projects hit is Clerk's per-user pricing once you outgrow its free tier. Staying on BetterAuth avoids that entirely, and a serverless database like Neon only adds cost once you outgrow its own free allowance too.

Scores

Popularity5/5

Next.js is the #1 React framework with 120k+ GitHub stars. Prisma is the most popular TypeScript ORM. PostgreSQL is ranked the most loved database for 5+ consecutive years. Combined, this is arguably the default SaaS stack in 2025.

Learning Curve3/5

Next.js App Router introduces new concepts (Server Components, Server Actions, route segments) that require reading the docs carefully. Prisma schema is intuitive. PostgreSQL SQL takes time to master for complex queries. Productive in 1–2 weeks, expert in 2–3 months.

Flexibility4/5

PostgreSQL handles everything from simple CRUD to complex analytics with CTEs and window functions. Next.js is agnostic about styling, state management, and auth. Prisma supports PostgreSQL, MySQL, and SQLite — adaptable to different hosting choices.

Performance4/5

Server Components eliminate client-side JS for data-fetching components, improving TTFB. PostgreSQL is fast with proper indexing. Vercel's edge network serves assets globally. Serverless cold starts are the main performance concern — mitigated by Railway's persistent processes.

Portability4/5

Runs on any Node.js host. PostgreSQL is available everywhere. Prisma is database-agnostic in design. Some Next.js features (ISR, edge middleware) are better supported on Vercel — minor friction when self-hosting, but fully solvable.

Tools in the Next.js + PostgreSQL Stack

Frontend Frameworks

Programming Languages

Database (choose one)

ORM (choose one)

Authentication (choose one)

Hosting (choose one)

Add-ons (optional — add any, or none)

CI/CD

Containerization

Observability

Email

Payments

Styling

Analytics

Next.js + PostgreSQL Pricing

Free to start

Next.js, TypeScript and PostgreSQL are open-source and free. Hosting on Vercel or Netlify is free to start, with Pro plans around $20/mo, and managed Postgres runs from about $6–15/mo if you don't self-host. Authentication can stay free with open-source BetterAuth, or use Clerk's free tier with paid plans from $25/mo.

Core frameworksFree (open source)

Next.js, TypeScript and PostgreSQL are free.

HostingFree–$20/mo

Vercel and Netlify have free tiers; Pro plans are about $20/mo for production.

Database (PostgreSQL)Free–$15/mo

Self-host for free, or use managed Postgres from about $6–15/mo.

AuthenticationFree tier available

BetterAuth is open-source; Clerk and Auth0 add free tiers, with paid plans from $25/mo and $35/mo.