Build, deploy and upgrade · senior
Deploying: Vercel vs self-hosting, environment variables and version skew
Next.js runs on Vercel, any Node server (next start, Docker), platforms through the stable Adapter API, or as a static export; self-hosting at scale means sharing caches across instances, keeping action keys and deployment ids stable, letting responses stream, and remembering that NEXT_PUBLIC_ values are frozen at build time.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Options: Vercel; Node server with
next start; Docker (oftenoutput: "standalone"for a small image); other platforms through Adapters (stable Adapter API and test suite in 16.2, plus OpenNext);output: "export"for a static site without server features. - Put a reverse proxy (nginx) in front for TLS, slow clients, rate limits; disable buffering so streaming works.
- Caches are per instance by default (memory + local disk). Multiple pods: configure
cacheHandler(ISR/route cache) andcacheHandlers("use cache"), e.g. Redis, setcacheMaxMemorySize: 0, and implementrefreshTagssorevalidateTagon one instance reaches all. - Same
NEXT_SERVER_ACTIONS_ENCRYPTION_KEYon all instances;deploymentIdfor version-skew protection (mismatch triggers a hard navigation); consistent build id across containers. 16.3 immutable static assets can be reused across deploys. - Env vars: server vars are read at runtime;
NEXT_PUBLIC_*are inlined at build. To promote one Docker image through environments, read server env at request time (await connection()) and expose needed values through your own API or props. - Load order:
process.env,.env.$(NODE_ENV).local,.env.local(not in test),.env.$(NODE_ENV),.env. - Edge vs Node: proxy is Node-only in 16 and
runtime = "edge"for routes is deprecated; data location matters more than compute location. after()work needs graceful shutdown (SIGTERM, drain 10-30 s). Image optimisation usessharpCPU on your servers.
The red pen
Common traps: mistake → fix
Mistake: "In-memory ISR cache works across pods"
Fix: each pod has its own copy; use a shared handler.
Mistake: "Change NEXT_PUBLIC_ values per environment at deploy time"
Fix: they were baked in at build.
Mistake: "Edge is always faster"
Fix: a far-away database adds round trips.
Easy to hard
Questions interviewers ask, easy to hard
- We must self-host Next.js on Kubernetes. What breaks or needs work compared with Vercel?
- Multiple pods: whose cache serves ISR, and how does
revalidateTagreach all pods? - What breaks during a rolling deployment, and how do you prevent it?
- How do you use one Docker image for staging and production?
- Edge runtime or Node runtime?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.