Skip to content
Tutorials Center
My learning

Topics

Lesson 71 of 72 ยท Practice and Interviews

Next.js Interview Questions

Next.js interview questions with concise answers on the App Router, Server Components, caching, rendering modes, Server Actions, proxy and deployment, plus runnable demos.

A Next.js interview is rarely about memorizing option names. Interviewers want to know whether you understand where code runs, when data is fetched, what gets cached and who is allowed to do what. If you can explain those four things with small examples, most follow-up questions answer themselves.

The questions below are grouped by topic, and each answer is short enough to say out loud in under a minute. The bold phrases are the points interviewers listen for. Follow the links when an answer feels thin: each one leads to the lesson that explains the idea properly. The page targets the App Router in Next.js 15 and 16, and mentions the older behavior where it still shows up in codebases.

What interviewers probe

Where it runs Server, browser or build time.
When data loads Build, request or navigation.
What is cached And what clears it.
Who may act Checks near the data.

Answer with these four and the details follow.

1 / 2

Fundamentals

1. What does Next.js add on top of React?

React renders components. Next.js adds the rest of an application: file-based routing, layouts, server rendering, data fetching, caching, Server Actions, image and font optimization, a build pipeline and deployment output. See What Is Next.js?.

2. What is the difference between the App Router and the Pages Router?

The Pages Router (pages/) renders pages as client components with special data functions such as getServerSideProps. The App Router (app/) is built on React Server Components: components are server-side by default, layouts nest and persist, and data is fetched with async/await inside components. Both can exist in one project during a migration. See Upgrading and Migrating from Pages Router.

3. What is a Server Component?

A component that renders only on the server. It can be async, read a database or secret directly, and its code is never sent to the browser: only its rendered output (the RSC payload) is. It cannot use state, effects, event handlers or browser APIs. See React Server Components.

4. What does 'use client' do?

It marks a boundary: this file and everything it imports run in the browser too, because they are included in the client bundle. It does not mean "client only": Client Components are still prerendered to HTML on the server. Put it on the smallest interactive piece, not on whole pages. See Client Components and "use client".

5. Can a Client Component contain a Server Component?

Not by importing it, because an import pulls it into the client bundle. But a Server Component can render a Client Component and pass a Server Component to it as children or another prop. The server renders the child, and the client component only places the result. See Composing Server and Client Components.

6. What can be passed from a Server Component to a Client Component as props?

Anything serializable: strings, numbers, booleans, null/undefined, bigint, Date, Map, Set, arrays, plain objects, Promises, and Server Actions. Not allowed: ordinary functions, class instances and symbols. Try the checker below.

Node.js Which props can cross the boundary?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

This is a stand-in for React's serializer, but the rule is real: a function written in a Server Component cannot be sent to the browser. See Inside the RSC Payload.

7. How do you keep secrets off the client?

Read secrets only in server code, and never prefix them with NEXT_PUBLIC_, because those variables are inlined into the browser bundle at build time. Put data and secret access in modules that import server-only, so importing them from a Client Component fails the build. See Keeping Server Code on the Server.

Routing

8. How does routing work, and which files are special?

Folders under app/ are URL segments, and a segment is public only when it contains a page file. Special files include layout, page, loading, error, not-found, template, route (an API endpoint) and default. See File-Based Routing.

9. How do dynamic routes work, and what changed in Next.js 15?

A folder like [slug] matches any single segment, [...slug] matches one or more and [[...slug]] matches zero or more. Since version 15, params and searchParams are Promises, so you await them in server code. See Dynamic Routes.

10. What are route groups and private folders?

(group) folders organize routes and let you give sections different layouts without changing the URL. _private folders are excluded from routing, which is useful for colocating components next to the routes that use them. See Route Groups and Private Folders.

11. What is the difference between a layout and a template?

A layout persists across navigations: its state is kept and it does not re-render when you move between its children. A template creates a new instance on every navigation, so state and effects reset. Use a template for things like enter animations or per-page logging. See Templates and Other Special Files.

12. What are parallel and intercepting routes?

Parallel routes (@slot folders) render several pages in one layout at the same time, each with its own loading and error states. Intercepting routes ((.)photo) show another route inside the current layout during client navigation, which is how you build a modal that is still a real URL on reload. See Parallel and Intercepting Routes.

It navigates on the client (a soft navigation that only fetches what changed), prefetches routes that scroll into view in production, and keeps layouts mounted. It still renders a real <a href>, so it works without JavaScript and for search engines. See Linking and Navigation.

Rendering and caching

14. Explain SSG, SSR, ISR and streaming.

SSG: HTML is built once at build time. SSR: HTML is built on each request. ISR: a static page that is rebuilt in the background after a time or an event. Streaming: the server sends HTML in pieces as parts become ready. In the App Router these are results of how you fetch and cache, not separate modes you pick. See SSG, SSR, ISR and Streaming Compared.

15. How does Next.js decide whether a route is static or dynamic?

A route that uses request-time data (cookies(), headers(), searchParams, connection()) or opts in with force-dynamic is rendered per request. Otherwise it is prerendered at build time. The build output marks each route. See Static vs Dynamic Rendering.

16. What are the caching layers in the App Router?

Four, in the classic model: request memoization (the same fetch or cache() call deduplicated within one render), the data cache (stored fetch results across requests), the full route cache (prerendered HTML and RSC payload of static routes) and the router cache (RSC payloads kept in the browser during navigation). See Caching in Next.js: the Big Picture.

17. What changed about caching in Next.js 15 and 16?

Version 15 made fetch requests and GET Route Handlers uncached by default, and stopped reusing page data in the client router cache by default. Version 16 introduces Cache Components, an opt-in model built around the use cache directive where caching is explicit and a page can mix static and dynamic parts. See The use cache Directive and Cache Components.

18. What is request memoization, and how is it different from the data cache?

Memoization lives for one request only: if three components call the same function with the same arguments while rendering, it runs once. The data cache survives across requests. For database calls, wrap the function in React's cache. Run the demo to see the scope.

Node.js Memoization lives for one request

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Three calls in request 1 hit the database once for user 7, plus one for user 8. Request 2 starts with an empty memo, so it asks again. See Data Access Layers and ORMs.

19. How do you refresh cached data after a change?

By time (cacheLife, or revalidate) or on demand: revalidatePath invalidates a route, revalidateTag invalidates everything with that tag, and in Server Actions updateTag expires the tag so the next read gets fresh data immediately. In version 16 revalidateTag takes a cache profile and refreshes in the background (stale-while-revalidate). See Revalidating Data.

20. What does Suspense add to streaming?

A <Suspense> boundary (or a loading.tsx file, which is a boundary for you) lets the server send the page shell immediately and stream slow parts later, so users see content sooner. Without boundaries the whole route waits for its slowest data. See Streaming with Suspense.

21. What is Partial Prerendering?

A route is split into a static shell served instantly from the edge and dynamic holes that stream in per request. In Next.js 16 it is part of the Cache Components model. See Partial Prerendering.

Actions and Route Handlers

22. What is a Server Action?

An async function marked 'use server' that runs on the server and can be called from a form or event handler. Under the hood it is an HTTP POST to the page's URL with an action id. It works in forms before JavaScript loads, which is progressive enhancement. See Server Actions.

23. Are Server Actions secure by default?

No more than any public endpoint. Anyone can send a POST with any arguments, so authenticate and authorize inside every action, and validate every input. Next.js adds protections (encrypted closed-over values, Origin checks), but they do not replace your checks. See Authorization and Data Security.

24. When do you use a Route Handler instead of a Server Action?

Use actions for mutations triggered by your own UI. Use a Route Handler (route.ts) when you need a public HTTP API: webhooks, a mobile client, file downloads, custom response types or CORS. Actions are not meant for reading data. See Route Handlers.

25. How do useActionState and useOptimistic help?

useActionState gives you the action's last result (field errors, messages) and a pending flag, and works with progressive enhancement. useOptimistic shows an expected result immediately and rolls it back if the action fails. See Building Forms with Server Actions and Optimistic UI.

26. Where should input validation live?

On the server, always. Client validation is a courtesy for the user. A schema library such as Zod can be shared by both sides. See Validating Input.

Middleware, proxy and auth

27. What are middleware and proxy.ts?

A file that runs before routes are matched and can redirect, rewrite, set headers or respond directly. Next.js 16 renamed middleware.ts to proxy.ts (function proxy), and it runs on the Node.js runtime. Use a matcher so it only runs for the paths that need it. See Middleware and the Proxy File.

28. Why is it unsafe to protect data only with middleware?

Because middleware is one layer and can be skipped or misconfigured. A 2025 vulnerability (CVE-2025-29927) let attackers bypass middleware with a crafted header on older versions. Pages, actions and handlers can also be reached through paths the matcher did not cover. Check the session where data is read.

29. Where should authentication checks go?

Use the proxy for a fast, optimistic redirect. Do the real check in a data access layer that every page, action and handler calls. See the full build in Project: Login and Protected Pages.

30. Sessions or JWTs?

A database session is a random id looked up on each request, so it can be revoked instantly. A signed JWT needs no lookup but stays valid until it expires. Choose database sessions when revocation matters. See Authentication and Sessions.

Optimization and deployment

31. Why use next/image?

It serves resized, modern-format images (WebP/AVIF), lazy-loads by default, and reserves space with width and height to prevent layout shift. Remote images need an allow-list in images.remotePatterns. See Image Optimization with next/image.

32. What does next/font solve?

It downloads fonts at build time and self-hosts them, with size-adjusted fallbacks, so there are no extra requests to Google and little layout shift. See Fonts and Third-Party Scripts.

33. What is a hydration mismatch?

The HTML from the server differs from what the client renders first. Causes: Date.now(), Math.random(), typeof window branches, locale-dependent formatting and invalid HTML nesting. Fix by rendering the same output on both sides and moving client-only values into an effect. See Debugging and Error Handling.

34. Node.js runtime or Edge runtime?

The default is Node.js: all APIs, any npm package. The Edge runtime starts faster and runs close to users, but has a limited API surface and size limits. Choose Edge only when its limits are fine and latency matters. See Node.js and Edge Runtimes.

35. How do you self-host Next.js?

Run next build and next start, or set output: 'standalone' to get a small server folder for a Docker image. Behind several servers you need a shared cache handler so ISR and revalidation stay consistent. See Self-Hosting and Docker.

36. How do environment variables work?

Variables in .env* files are available to server code. Only those starting with NEXT_PUBLIC_ are inlined into the client bundle at build time, so changing them requires a rebuild. See Environment Variables and Secrets.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does adding 'use client' to a file do?

    'use client' marks a boundary: the file and everything it imports are sent to the browser. Client Components are still prerendered to HTML on the server.
  2. 2. Which value cannot be passed as a prop from a Server Component to a Client Component?

    Ordinary functions cannot be serialized. Server Actions are the exception, because React sends a reference to them.
  3. 3. A Server Action needs a security check. Where does it belong?

    An action is a public POST endpoint. It must authenticate, authorize and validate on its own.
  4. 4. Which statement about request memoization is true?

    Memoization is per request. The next request starts empty, which is different from the cross-request data cache.
  5. 5. Why can changing a NEXT_PUBLIC_ variable require a new build?

    Public variables are replaced in the bundle during the build, so the running app cannot pick up a new value.

Summary

  • Explain every topic through four ideas: where code runs, when data loads, what is cached and who may act.
  • Server Components are the default. 'use client' creates a boundary, and only serializable props cross it.
  • The classic caching layers are memoization, the data cache, the full route cache and the router cache. Version 15 made fetching uncached by default, and version 16 adds explicit use cache.
  • Server Actions and Route Handlers are public endpoints: authenticate, authorize and validate inside them.
  • Middleware (now proxy.ts) is a convenience, never the only guard.
  • Know the deployment basics: Node versus Edge, standalone output, shared cache handlers and NEXT_PUBLIC_ inlining.

Next: Next.js Cheat Sheet