Skip to the solution
MediumSystem Design6 min read

How do you deploy a Next.js app (Vercel vs self-hosted)?

174 views

The problem

Question presented to candidate: "We are choosing between Vercel and running Next.js on our own Kubernetes cluster. What do we get on each, and what must we set up ourselves when self-hosting?"

What a strong answer should cover:

  • Deployment options: a managed platform (Vercel or another provider with Next.js support), a Node.js server (next start), a Docker image (usually with output: "standalone"), or a static export (output: "export").
  • Every server feature works self-hosted with next start: SSR, streaming, ISR, Server Actions, Route Handlers, Proxy and image optimization.
  • Self-hosting responsibilities: caching across instances (a shared cacheHandler), a CDN for static assets, TLS, scaling, logs and metrics.
  • Static export produces plain files but drops server features: no Server Actions, dynamic routes without params, request-time rendering, ISR, redirects or rewrites.
  • Version skew between deployments (old clients calling new servers) needs deploymentId or careful rollouts.

Clarifying questions expected:

  • "Do we need ISR, Server Actions or request-time rendering?" β€” they rule out static export.
  • "How many instances will run?" β€” more than one needs a shared cache.

Code / implementation expected: Yes β€” a Dockerfile for standalone output.

  • nextjs
  • deployment
  • vercel
  • self-hosting

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

6 min read Β· 8 sections

Read the code

A Dockerfile for standalone output
# next.config.ts:  const nextConfig = { output: "standalone" };

FROM node:24-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:24-alpine AS run
WORKDIR /app
ENV NODE_ENV=production PORT=3000 HOSTNAME=0.0.0.0
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
EXPOSE 3000
CMD ["node", "server.js"]

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 88 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextMedium

What is the difference between layout.js and template.js in Next.js?

Continue