Deploying Next on Vercel
Deploy Next.js on Vercel: git integration, env vars, previews, build cache, and production checklist.
- nextjs
- deploying-next
Vercel is the platform that ships first-class support for Next.js features (ISR, middleware edge, image optimization, streaming). Deploying well is mostly git + env + build correctness, not special config.
Docs: Deploying, Vercel Next.js.
Typical flow
- Import the GitHub/GitLab/Bitbucket repo in Vercel.
- Framework preset: Next.js (auto-detected).
- Set Environment Variables for Production / Preview / Development.
- Push to main → production deploy; PR → preview URL.
# local production check
next build && next start
Catch build-only errors before CI burns minutes.
Environment variables
Mirror secrets from env docs. Preview deployments need their own DB/auth config or shared staging — do not point previews at production databases casually.
Build and output
next buildcompiles server/client graphs and static pages.- Image optimization and middleware run on Vercel’s infrastructure.
- Check Functions region if latency-sensitive.
Preview best practices
| Practice | Why |
|---|---|
| Protect production env secrets | Previews should not get prod keys by default |
| Use preview DB | Avoid mutating real user data |
| Check mobile on preview URLs | Catch layout before promote |
Common failures
- Missing env at build time for
NEXT_PUBLIC_*. - Node version mismatch — set in project settings /
package.jsonengines. - Relying on local filesystem writes — serverless is ephemeral.
- Wrong root directory in monorepos.
Interview out-loud
“I deploy Next on Vercel via git integration with separate preview and production envs, run next build locally to verify, keep secrets out of NEXT_PUBLIC_, and treat serverless as stateless. Previews validate PRs before production.”
Related on this site
Further reading
Edge cases worth rehearsing
Interviewers and production incidents cluster around the same edges: first render versus update, empty and loading states, Strict Mode double setup, concurrent interruptions, and what happens when identity (key, route params, user id) changes mid-edit. Walk one concrete user journey end-to-end — open, edit, navigate away, come back — and say which state survives.
Prefer fixing data flow and ownership before reaching for memoization or micro-optimizations. Prefer event handlers over effects when a user action is the trigger. Prefer deriving values during render over mirroring props into state. Prefer stable list keys from business ids. Measure with the profiler when performance is the claim.
When you cite an API, mention one failure mode: abort on unmount, serializable props across server/client boundaries, focus restoration for dialogs, or cache invalidation after a mutation. Specific beats generic every time.
Edge cases worth rehearsing
Interviewers and production incidents cluster around the same edges: first render versus update, empty and loading states, Strict Mode double setup, concurrent interruptions, and what happens when identity (key, route params, user id) changes mid-edit. Walk one concrete user journey end-to-end — open, edit, navigate away, come back — and say which state survives.
Prefer fixing data flow and ownership before reaching for memoization or micro-optimizations. Prefer event handlers over effects when a user action is the trigger. Prefer deriving values during render over mirroring props into state. Prefer stable list keys from business ids. Measure with the profiler when performance is the claim.
When you cite an API, mention one failure mode: abort on unmount, serializable props across server/client boundaries, focus restoration for dialogs, or cache invalidation after a mutation. Specific beats generic every time.
Related guides
- Auth Patterns OverviewAuth in Next.js App Router: cookies/sessions, middleware gates, server checks, and avoiding client-only security theater.
- Caching in Next.js OverviewNext.js caching layers: request memoization, data cache, full route cache, and router cache — what invalidates each.
- Client Components in Next.jsClient Components in the App Router: use client, hydration, bundling boundaries, and patterns that keep JS small.
- Data Fetching Patterns App RouterFetch data in Server Components with async/await and fetch caching: colocation, parallel requests, and client fallbacks.
- Edge Runtime TradeoffsEdge Runtime vs Node.js in Next.js: cold starts, API limits, middleware, and when Node is the right default.