Deploying on Vercel
Deploy a Next.js app with Git-based deploys, preview URLs per pull request, environment variables and edge caching.
Intermediate · about 3 hours · difficulty 2/5
Learn first: Environments, Config and Secrets, Data Fetching and Caching in Next.js
Vercel is built by the team behind Next.js and is the fastest way to put a Next.js app online. Connect a GitHub repo and every push deploys.
How it works
- Pushing to main creates a production deployment; every pull request gets a preview URL you can share with reviewers.
- Pages and route handlers run as serverless or edge functions; static assets are served from a global CDN.
- Environment variables are set per environment (development, preview, production).
- Instant rollback to any previous deployment if something breaks.
Connecting a database
Use a hosted PostgreSQL (Neon, Supabase or another provider) with a pooled connection string, because each function instance may open its own connections. Run migrations in a build step or a CI job, not on every function start.
Know the limits
The free Hobby plan is for personal, non-commercial projects. Functions have execution time limits, and long-running WebSocket servers or heavy background work do not fit. Pair Vercel with a separate worker or service for those.
Pitfalls
- Exhausting database connections from serverless functions without pooling.
- Forgetting to set environment variables for the preview environment.
- Building commercial products on the Hobby plan.
You are ready to move on when your Next.js portal deploys from GitHub with preview URLs on pull requests, a managed PostgreSQL database and migrations applied automatically.
Key concepts
- Git-based deployments
- Preview deployments
- Environment variables per environment
- Serverless and edge functions
- Database connection pooling
- Rollbacks
- Netlify
Other options for this step
- Deploying on Render or Railway: Deploy long-running Node.js servers, background workers and PostgreSQL on a platform-as-a-service from a Git repo or Dockerfile.
Mini project
Deploy your Next.js placement portal to Vercel with a hosted PostgreSQL database, preview deployments on pull requests, and a CI step that applies migrations before production deploys.
Check yourself
Your Vercel app works for a few users but starts failing with 'too many connections' during a traffic spike. What is happening and how do you fix it?
Free resources
- Vercel Documentation (Vercel)
- Deploying Next.js (Next.js)