Skip to content

Lesson 27 of 27Production Next.js

Wrap-Up: Next.js

Tie the Next.js course together: one realistic full-stack feature taken from route to production, a mixed review, and where to go next.

14 min read0/6 questions

You started this course asking what React alone leaves you to solve. Since then you have learned how Next.js renders, split work between server and client, built routes, layouts and streaming UI, fetched, cached and mutated data, and then structured, deployed, secured, tested and observed a real app. On the job these never arrive one lesson at a time. This lesson lines them up once more and uses them together on one feature.

The path you took

The Next.js course, unit by unit
  1. Unit 1

    Foundations

    Rendering strategies, Server and Client Components, the App Router and layouts gave you the mental model every later lesson builds on.

  2. Unit 2

    Routing in depth

    Dynamic routes, URL state, parallel routes, streaming and error files turned that model into real pages that load fast and fail well.

  3. Unit 3

    Full-stack

    Caching, Server Actions, Route Handlers, databases, metadata, i18n, auth and the Pages Router made the app read and write real data safely.

  4. Unit 4

    Shipping

    A project structure that scales and a deploy to Vercel or Docker took the app from your laptop to the internet.

  5. Unit 5

    Production Next.js

    Security, testing, performance and observability kept it safe, correct, fast and visible once real users arrived.

How it fits together

The ticket: "Our B2B billing app needs an Invoices area. Each customer company sees only its own invoices, can filter them, open one in a modal or on its own page, and mark one as paid. The payment provider also sends a webhook when a card payment succeeds. The old invoice list lives in pages/ and is slow." Here is how the course shows up, in the order you would really work.

Choosing where the code goes. The feature gets its own folder under a (dashboard) route group, with queries in a server-only data layer, as Next.js Project Structure laid out. The old pages/invoices.tsx used getServerSideProps and SWR. Following The Pages Router and Migrating to App Router, you move just this section to app/, turning the data function into an async Server Component.

Rendering the list. The list page is a Server Component that reads from the database directly, the default from Server and Client Components. Only the filter controls and the "mark paid" button are Client Components, so the table ships no JavaScript. Filters, sort and page number live in the URL, parsed and validated on the server as Search Params and URL State taught, so a finance manager can bookmark "unpaid invoices over 30 days". The page shell is static and the table streams in behind a Suspense boundary with a skeleton, the pattern from Rendering Strategies and Streaming, Loading UI and Instant Navigations.

Opening an invoice. app/invoices/[id]/page.tsx awaits its params, loads the invoice and calls notFound() for an unknown ID, as Dynamic Routes and Static Generation described. From the list, an intercepting route shows the same invoice in a modal with a real URL, so refresh and sharing still work, which is the modal pattern from Parallel and Intercepting Routes. An error.tsx beside the page catches a failed load without taking down the layout, from Error Handling in Next.js.

Getting the data right. Every query goes through the Data Access Layer from Databases and the Data Access Layer, which checks the session and filters by the user's company before touching a row. This is the real authorization check. proxy.ts only does an optimistic redirect for signed-out users, as Auth and Proxy warned. Invoice reads are cached with use cache and tagged per company, following Data Fetching and Caching and Cache Components in Depth, so one company's change never invalidates another's.

Marking an invoice paid. The button submits a Server Action. It validates input with Zod, re-checks auth and ownership in the DAL, writes in a transaction with an idempotency key, then calls revalidateTag so the list and the detail page refresh, all from Server Actions and Forms. useActionState shows pending and error states, and useOptimistic flips the badge immediately. Securing a Next.js App is the reminder why the action checks everything itself: it is a public endpoint anyone can call.

Receiving the webhook. The payment provider posts to app/api/payments/webhook/route.ts. The Route Handler verifies the signature on the raw body, ignores duplicate event IDs and revalidates the same tag, as Route Handlers showed. A browser never calls this endpoint, which is why it is a handler and not an action.

The details users notice. The invoice page sets its title with generateMetadata, sharing the fetch with the page, from Metadata and Images. Amounts and dates are formatted per locale from the [lang] segment, as Internationalization in Next.js taught.

Proving and shipping it. Vitest covers the Zod schema and calls the Server Action directly with a fake session to check that a user from another company is refused. Playwright runs the filter, modal and mark-paid flow against a production build, as Testing Next.js Apps recommended. The bundle analyser shows a date library leaking into the client, which you move to the server to protect INP, from Performance and Bundle Size in Next.js. CI builds one standalone image and deploys it, following Deploying Next.js.

Watching it in production. A week later, onRequestError reports a spike on the webhook route with a trace ID. The trace from Observability and Running Next.js in Production shows the database timing out under a burst of retries, and the idempotency key you added earlier is why no invoice was marked paid twice.

No lesson worked alone. The server-first rendering kept the bundle small, the DAL made both the action and the page safe, cache tags tied the webhook to the UI, and observability caught the one thing tests could not. That is Next.js at work.

Check yourself

Quick check
A component renders an invoice table from the database and has one filter dropdown that uses useState. What is the best split?
Need a nudge? A hint rules out a wrong answer.
Predict the outputJavaScript

What does this log?

const p = new URLSearchParams("status=paid&status=open&page=2");
console.log(p.get("status"), p.getAll("status").length, typeof p.get("page"));
Need a nudge? Hints walk you through it.
Match the pairs0/6 matched

Match each file to its job.

Choose an item, then its match on the other side.
Put it in order5 steps

Put the steps of a safe 'mark as paid' Server Action in order.

  1. Tap the steps below in the right order.
Need a nudge? A hint shows where it starts.
Quick check
A teammate puts the payment provider's secret key in NEXT_PUBLIC_PAYMENT_KEY so a Client Component can read it. What happens?
Need a nudge? A hint rules out a wrong answer.
Quick check
Where should the check that a user can only see their own company's invoices live?
Need a nudge? A hint rules out a wrong answer.

What you can do now

  • Pick a rendering strategy per page and explain it, from static to streamed to partially prerendered.
  • Split an app into Server and Client Components without leaking secrets or shipping needless JavaScript.
  • Build routes with dynamic segments, URL state, modals with real URLs, loading UI and error boundaries.
  • Read and write data safely with a Data Access Layer, cached reads, Server Actions and Route Handlers.
  • Work on an older Pages Router codebase and migrate it route by route.
  • Deploy to Vercel or Docker, and test, measure and monitor the app once it is live.

That is a solid mid-level grasp of Next.js. What you do not have yet is the experience of running one app through several major upgrades or a traffic spike. That comes from real work.

Mistakes that still catch people

  • 'use client' too high in the tree. One directive in a layout turns a whole section into client code. Revisit Server and Client Components.
  • Trusting the proxy for auth. It is an optimistic check, not a security boundary. Revisit Auth and Proxy and Securing a Next.js App.
  • Caching per-user data in a shared cache. A missing key or tag shows one user another's data. Revisit Cache Components in Depth.
  • Forgetting to revalidate after a write. The mutation works and the page still shows old data. Revisit Server Actions and Forms and Data Fetching and Caching.
  • Testing only the dev server. Caching and streaming behave differently in a production build. Revisit Testing Next.js Apps.
  • Self-hosting several instances without a shared cache. Revalidation reaches one pod and the rest serve stale pages. Revisit Observability and Running Next.js in Production.

Where to go next

The natural next course is Algorithms & Patterns if coding interviews are coming, and Design & Architecture if you want to structure larger apps and services. System Design shows how a Next.js front end fits into caches, queues and databases at scale, and Docker and AWS go deeper on the self-hosting you saw here.

Real practice matters as much as the next course:

  • Finish and extend Project: A Neighbourhood Tool Library. Its "Make it yours" list adds a real database, signed sessions and a deploy.
  • Build more in the Project Lab. Its Next.js builds take you from a habit tracker to a full stack monorepo with FastAPI and Postgres.
  • Build and deploy a full-stack app. Auth, a database, a form with a Server Action, a webhook and tests, live on a real URL you can show.
  • Migrate something. Take an older Pages Router project, yours or open source, and move one section to the App Router.
  • Read the official docs. nextjs.org/docs, and the release notes for each version, change faster than any course.
Key terms
Server Component
A component that runs only on the server, can read data directly and sends rendered output, not its code, to the browser.
client boundary
The file marked 'use client' where the tree switches to components that ship JavaScript and can use hooks.
Data Access Layer
A server-only module that every read and write goes through, where authentication and authorization are checked.
cache tag
A label attached to cached data so a later revalidateTag call can invalidate every entry with it.
Server Action
A server function the browser can call, usually from a form, which must validate and authorize like any public endpoint.
streaming
Sending HTML in chunks so the shell appears at once and slower parts fill in as their data arrives.
standalone output
A next build mode that bundles the server and only the dependencies it needs, ready for a small Docker image.