20 questions covering rendering, caching, Server Components, security and performance, from fundamentals to senior-level design. Read the answers, then test yourself in a timed, AI-graded mock interview.
What is the difference between SSR, SSG, ISR and CSR in Next.js?
SSR renders HTML on every request. SSG renders once at build time. ISR serves a static page and regenerates it in the background after a revalidate interval or on demand. CSR renders in the browser after the JavaScript loads. In the App Router, these map to dynamic rendering, static rendering, and fetch/route-level revalidation.
What are React Server Components and why does Next.js use them?
Server Components run only on the server, so their code and dependencies are never sent to the browser. They can read databases or secrets directly and reduce client bundle size. Interactivity lives in Client Components, marked with "use client".
When should a component be a Client Component?
When it needs state, effects, event handlers, browser APIs, or a library that depends on them. Keep Client Components as small leaves of the tree and pass server-rendered content in as children to keep the bundle small.
What is the difference between the Pages Router and the App Router?
The Pages Router uses getServerSideProps, getStaticProps and file-based pages. The App Router uses nested layouts, Server Components by default, streaming with Suspense, loading and error boundaries, and the fetch-based caching model.
Data fetching & caching
How does caching work in the Next.js App Router?
There are several layers: request memoization (deduplicating identical fetches in one render), the data cache (persisted fetch results), the full route cache (static HTML and RSC payload) and the client router cache. Defaults have changed across Next.js versions, so state which version you are describing and how to opt in or out with revalidate, cache options and tags.
How do you revalidate data on demand?
Tag fetches or cached functions and call revalidateTag, or call revalidatePath, from a Server Action or Route Handler after a mutation. Use time-based revalidate when freshness can be approximate.
What are Server Actions and what are their risks?
Server Actions are async functions that run on the server and can be called from forms or client code. Treat them as public endpoints: validate input, check authentication and authorization inside every action, and protect against CSRF and over-posting.
How do you avoid request waterfalls?
Start independent fetches in parallel with Promise.all, fetch in the components that need the data, and use Suspense boundaries so slow data streams in without blocking the rest of the page.
Routing, middleware & security
What does middleware do and when does it run?
Middleware runs before a request completes, on the edge runtime by default. Use it for redirects, rewrites, header changes, A/B routing and lightweight auth checks. Keep it small, because it runs on matched requests and has runtime limits.
How do dynamic routes, route groups and parallel routes differ?
Dynamic segments like [slug] capture URL params. Route groups like (marketing) organize files without changing the URL. Parallel routes (@slot) render multiple pages in one layout, and intercepting routes enable patterns such as modals.
How would you implement authentication in Next.js?
Use a session cookie (httpOnly, secure, sameSite) or a library such as Auth.js. Verify the session in Server Components, Route Handlers and Server Actions. Do not rely on middleware alone, and never trust client-side checks.
How do you protect environment variables?
Only variables prefixed with NEXT_PUBLIC_ are exposed to the browser. Keep secrets unprefixed, read them only in server code, and never import server-only modules into Client Components (the server-only package enforces this).
Performance & SEO
How do you improve Core Web Vitals in a Next.js app?
Use next/image with a priority image above the fold, next/font to avoid layout shift, stream with Suspense, reduce client JavaScript by keeping components on the server, and load third-party scripts with next/script and a lazy strategy.
How does next/image help performance?
It serves responsive sizes, modern formats (WebP/AVIF), lazy loads by default, and reserves space to prevent layout shift. Mark the LCP image with priority.
How do you handle SEO metadata in the App Router?
Export a metadata object or generateMetadata for per-page titles, descriptions, canonical URLs and Open Graph tags. Add app/sitemap.ts and robots rules, and use structured data (JSON-LD) in the page.
What is generateStaticParams and when do you use it?
It tells Next.js which dynamic route params to pre-render at build time, so those pages are static. Combine it with revalidate or dynamicParams to control what happens for params you did not pre-render.
Architecture & senior-level questions
How would you design a large Next.js app for multiple teams?
Split by route groups and feature folders, share a design system as a package, enforce server/client boundaries, set clear data-access layers, and use CI checks for bundle size and Core Web Vitals.
How do you handle errors and loading states?
Use loading.js for Suspense fallbacks, error.js as route-level error boundaries, and not-found.js for 404s. Log server errors centrally and keep user-facing messages safe.
When would you choose a Route Handler over a Server Action?
Use Route Handlers for public or third-party HTTP APIs, webhooks, and non-form clients. Use Server Actions for mutations triggered from your own UI.
What would you check when a Next.js page is slow in production?
Look at the server timing and data fetches (waterfalls, uncached queries), the client bundle (analyze large dependencies), image and font loading, third-party scripts, and the cache headers on the route.
Turn answers into an offer
Knowing the answer is not the same as explaining it under time pressure. MockExperts runs a live AI interviewer, grades your reasoning against a rubric, and gives you a clear HIRE / NO HIRE verdict with specific feedback.