Skip to article content
FrontendXLesson 20 / 20

Deployment and the Capstone Runbook

A version-qualified path through the Next.js App Router: server components, client boundaries, data fetching, caching layers, streaming, error handling, proxy, images, performance, testing and deployment, with the Next.js 15 and 16 behavior changes called out where they matter.

advanced · about 50 minutes · 6 exercises

  • Predict
  • Explain
  • Implement
  • Debug
  • Test
  • Interview

What you will be able to do

#
  • Explain what the default build produces and when output: standalone is the right choice.
  • Separate build-time and runtime environment configuration in a deployment without leaking secrets.
  • Assemble a complete pre-deploy and post-deploy runbook for a Next.js 16 application.

Overview

#

What the build produces

next build emits two kinds of output: static assets (prerendered HTML, JavaScript, CSS, fonts, images) that any CDN or static host can serve, and server output (route handlers, server actions, dynamic rendering) that needs a Node.js process. The default output bundles the server with its full dependency tree. Setting output: "standalone" in next.config produces a minimal standalone folder containing only the traced dependencies, which is the right choice for containerized deployments where image size and cold start matter:

snippet.js
// next.config.js
module.exports = {
  output: "standalone",
};

A container then runs node server.js from the standalone folder and copies the static and public asset folders into place. Everything static should still be served from a CDN in front of the server, not through the Node process.

Environment split in production

The build-time versus runtime distinction from the config lesson becomes an operational rule in deployment. NEXT_PUBLIC_ values must be present in the environment at build time, because they are inlined then; a deployment pipeline that bakes the build before injecting env ships an app pointing at the wrong API. Server-only secrets are the opposite: they must exist at runtime in the platform's secret store and must never appear in the build environment of a public CI job. Auditing this split is a standard pre-deploy step: list every process.env read, classify it as build-time public or runtime secret, and verify the pipeline provides each at the right moment.

Caching at the edge

In front of the server sits a CDN. Static assets get immutable, long-lived cache headers keyed by content hash, so deploys are instant for returning visitors. Prerendered and revalidated pages follow the caching layers you configured in the app: ISR revalidation, tag-based revalidation and explicit cache headers. A stale-data incident in production is almost always one of these layers serving old content, which is why the capstone runbook includes a cache verification step rather than trusting a single curl.

The version-qualified recap

You now know the full modern baseline. Next.js 15 made the request APIs async, stopped caching fetch and GET route handlers by default, and introduced the first caching-layer changes. Next.js 16 removed synchronous request API access entirely, made Turbopack the default bundler, renamed middleware to proxy, introduced Cache Components behind the cacheComponents flag, required explicit images.qualities for non-default qualities, deprecated images.domains for remotePatterns, and removed AMP support and the next lint command. A runbook written against Next.js 14 assumptions will mislead a Next.js 16 deployment; version qualification is part of operational competence.

The capstone runbook

Assemble everything into an ordered checklist: typecheck and ESLint (via the CLI, since next lint is gone), the full build with Turbopack, a preview-environment smoke test of the critical routes, the environment audit, the deploy, post-deploy verification of key routes and cache behavior, and a rehearsed rollback. The capstone exercises below make you predict, implement, debug, test and defend this runbook.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Predict

    A page calls cookies() to read a session. The team adds the page to a fully static prerender attempt (no dynamic APIs anywhere else). What happens during next build, and what is the page's rendering mode in production?

    Choose the best answer
  2. Exercise 2Explain

    Explain how you would configure build-time and runtime environment variables for a Next.js app deployed to a container platform, and what your pipeline must guarantee for each.

    Reveal the reference answer
    reference.text
    Build-time: every NEXT_PUBLIC_ variable must be present in the build job's environment before next build runs, because the values are inlined into the client bundle at that moment; the pipeline must therefore inject public config before the build step and rebuild whenever those values change. Runtime: server-only secrets (database URLs, API keys, session secrets) live in the platform's secret store and are injected into the running container; they must never be present in a public CI build environment or prefixed with NEXT_PUBLIC_. The guarantee for each: public values are baked correctly into the shipped bundle, secrets exist only at runtime and never in client code or build logs.

    Authored expected output: A two-sided answer: public config before build with rebuild-on-change, secrets at runtime in a secret store, and no crossover.

    The split is temporal (when the value is consumed) and structural (where the value is allowed to appear).

  3. Exercise 3Implement

    Write the deployment runbook for a Next.js 16 app as an ordered checklist. Include: pre-build checks (types, lint via the correct command for Next 16), the build, the environment audit, a preview smoke test, the deploy, post-deploy verification (routes and cache behavior), and rollback.

    starter.text
    # Deployment runbook
    1. # TODO: pre-build checks
    2. # TODO: build
    3. # TODO: environment audit
    4. # TODO: preview smoke test
    5. # TODO: deploy
    6. # TODO: post-deploy verification
    7. # TODO: rollback

    Reveal the reference answer
    reference.text
    # Deployment runbook (Next.js 16)
    1. Pre-build: run the TypeScript compiler in check mode and ESLint via the CLI (npx eslint .) since next lint was removed in Next.js 16; block on any error.
    2. Build: run next build with Turbopack (the default in 16); confirm the static/dynamic route summary matches expectations.
    3. Environment audit: list every process.env read; confirm NEXT_PUBLIC_ values are present at build time and server secrets exist only in the runtime secret store.
    4. Preview smoke test: deploy to a preview environment; load the critical routes; verify a dynamic page, a static page and one route handler.
    5. Deploy: promote the same build artifact to production; never rebuild between preview and production for public env parity.
    6. Post-deploy: verify key routes return 200 with expected content; verify cache behavior (fresh data after revalidation, immutable assets hit the CDN); watch error rates.
    7. Rollback: keep the previous artifact deployable; rehearse the rollback command so recovery is one step, not an investigation.

    Authored expected output: An ordered runbook naming the Next 16 lint replacement, the env split audit, artifact promotion and a rehearsed rollback.

    The runbook operationalizes the course: version-qualified commands, the build/runtime env split, layered cache verification and recovery.

  4. Exercise 4Debug

    After a routine deploy, the app builds and starts, but every client page calls the wrong API host and the error appears only in production. The pipeline injects all environment variables at container start. Find the flaw. # pipeline (simplified) - docker build . # runs next build inside the image - docker run -e NEXT_PUBLIC_API_BASE=https://api.prod.example.com ...

    starter.text
    # pipeline (simplified)
    - docker build .            # runs next build inside the image
    - docker run -e NEXT_PUBLIC_API_BASE=https://api.prod.example.com ...

    Reveal the reference answer
    reference.text
    NEXT_PUBLIC_API_BASE is a build-time variable: it is inlined into the client bundle during next build inside docker build, where the variable was not set, so the bundle baked the empty or fallback value. Injecting it at docker run only affects server-side runtime env, which the client never reads. Fix by providing NEXT_PUBLIC_ values to the build step (build args or build-time env), or by making the API base a runtime server-side concern (a route handler or server component reads it and the client calls same-origin endpoints).

    Authored expected output: The client bundle contains the build-time (empty or fallback) value; supplying the variable at build time or routing client calls through the server fixes it.

    The env split is temporal: public values are consumed by the compiler, so they must exist when the compiler runs, not when the container starts.

  5. Exercise 5Test

    Write a pure function auditEnv(vars: Record<string, { value: string | null, atBuild: boolean, isPublic: boolean }>) that returns a list of problems: a public variable missing at build time, a secret (not public) that is marked atBuild, and any variable with a null value. Write assertions covering all three problem types and a clean config.

    starter.ts
    export function auditEnv(vars: Record<string, { value: string | null, atBuild: boolean, isPublic: boolean }>): string[] {
      // TODO
    }
    
    // assertions
    // const clean = { API_BASE: { value: 'https://x', atBuild: true, isPublic: true }, DB_URL: { value: 'postgres://...', atBuild: false, isPublic: false } }
    // expect(auditEnv(clean)).toEqual([])

    Reveal the reference answer
    reference.ts
    export function auditEnv(vars: Record<string, { value: string | null, atBuild: boolean, isPublic: boolean }>): string[] {
      const problems: string[] = [];
      for (const [name, spec] of Object.entries(vars)) {
        if (spec.value === null) problems.push(`${name}: missing value`);
        if (spec.isPublic && !spec.atBuild) problems.push(`${name}: public variable must be present at build time`);
        if (!spec.isPublic && spec.atBuild) problems.push(`${name}: secret must not be baked at build time`);
      }
      return problems;
    }
    
    // The three rules encode the env split: public values are consumed by the compiler,
    // secrets are consumed at runtime, and nothing may be missing.

    Authored expected output: The clean config returns []; each violation type produces exactly one problem string.

    Encoding the deployment rules as a testable function turns the environment audit from tribal knowledge into an executable check.

  6. Exercise 6Interview

    Interview question: you own the launch of a high-traffic Next.js 16 app next week. What do you verify before, during and after launch day?

    Reveal the reference answer
    reference.text
    Before: performance budgets verified on the production build (not dev), the static/dynamic route map reviewed so no hot page accidentally renders dynamically, the caching strategy tested including revalidation behavior under load, the environment audit clean, error tracking and alerts wired, load tests on route handlers and server actions, and the rollback rehearsed. During: real-time dashboards for error rate, latency and cache hit ratio; a freeze on config changes; a runbook owner for each alert. After: compare field Core Web Vitals against the pre-launch baseline, review cache and revalidation logs for surprises, confirm the version-qualified assumptions (Next 16: Turbopack build, proxy convention, Cache Components flag state) held in production, and write down every incident for the next runbook revision.

    Authored expected output: A three-phase answer covering pre-launch verification (budgets, route map, caching, rollback rehearsal), launch-day observability and freeze, and post-launch field-data comparison.

    Strong answers treat launch as an operational process with measurable gates, not a deploy command.

Common misconceptions

#
  • output: standalone changes how the app behaves. It only changes the shape of the server output for containerized deployment; runtime behavior is identical.
  • Production environment variables are all read at runtime. NEXT_PUBLIC_ values are frozen at build time, so the build environment must already contain them.

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.