>_
EngineeringNotes
Back to Next.js Hub

Next.js Interview Mastery

A comprehensive engineer's guide to passing high-level Next.js interviews. From core fundamentals to advanced full-stack architecture.

Fundamentals

Q1.

What is Next.js?

AnswerNext.js is a React-based full-stack framework that provides server-side rendering, static generation, routing, API routes, and performance optimizations out of the box.

Q2.

Why use Next.js over React?

AnswerKey advantages include built-in routing, SSR/SSG support, integrated backend APIs, and out-of-the-box performance optimizations (Image, Font, Script).

Q3.

What is App Router?

AnswerApp Router is the modern routing system in Next.js (introduced in v13) that uses folder-based routing, React Server Components (RSC), and nested layouts for better state management and performance.

Routing & Layout

Q1.

Explain file-based routing

AnswerRouting is determined by the folder structure within the /app directory. For example, /app/about/page.js corresponds to the /about route.

Q2.

What are dynamic routes?

AnswerRoutes that use dynamic segments. For example, /app/blog/[id]/page.js matches /blog/123, /blog/abc, etc.

Q3.

How do layouts work?

AnswerLayouts (layout.js) are shared UI components that wrap pages. They preserve state during navigation and can be nested to create hierarchical UI structures.

Root Layout
Dashboard Layout
Page

App Router vs Pages Router

Q1.

What are the primary differences?

AnswerThe App Router uses React Server Components by default, supports nested layouts, and simplifies data fetching. Pages Router relies on getServerSideProps/getStaticProps and a flatter layout structure.

FeatureApp RouterPages Router
LayoutNested (layout.js)Manual (Custom _app)
Data FetchDirect (async/await)getStatic/ServerProps
ComponentsServer-firstClient-first

Server vs Client Components

Q1.

What are Server Components?

AnswerComponents that run only on the server. No JavaScript is sent to the client, resulting in faster initial loads and zero impact on bundle size.

Q2.

What are Client Components?

AnswerComponents that run in the browser. They allow for interactivity, event listeners, and browser APIs.

Q3.

When should you use 'use client'?

AnswerUse it when you need interactivity (onClick, onChange), React Hooks (useState, useEffect), or Browser-only APIs (window, localStorage).

Q4.

Can Server Components use hooks?

Answer❌ No. useState, useEffect, and other interactive hooks are strictly client-side only.

Hydration

Q1.

What is hydration?

AnswerIt's the process where React in the browser takes the static HTML rendered on the server and attaches event listeners/state to make it an interactive application.

ServerClient
HTML
JS Loads
Hydrated
Q2.

What is a hydration mismatch?

AnswerThis happens when the HTML generated on the server doesn't match the first render on the client (e.g., using new Date() or window.innerWidth directly in the JSX).

Rendering Strategies

Q1.

SSR vs CSR?

AnswerSSR (Server-Side Rendering) generates HTML on every request for SEO and performance. CSR (Client-Side Rendering) downloads JS and renders in the browser for snappy transitions after the initial load.

Q2.

What is ISR (Incremental Static Regeneration)?

AnswerISR allows you to update static pages after you've built your site. You can revalidate specific pages in the background without needing a full rebuild.

Data Fetching & Caching

Q1.

How do you fetch data in App Router?

AnswerYou can use the native fetch API directly inside async Server Components.

tsx
tsx
const data = await fetch(url);
Q2.

What are caching strategies?

AnswerNext.js extends fetch to include caching options: 'force-cache' (default), 'no-store' (dynamic), and revalidation duration.

Q3.

Explain ISR with code

AnswerSet constant revalidation time for a route or specific fetch call.

tsx
tsx
fetch(url, { next: { revalidate: 60 } });
Q4.

What is tag-based revalidation?

AnswerAllows you to purge specific cache entries across your entire app by assigning tags to fetch requests.

tsx
tsx
fetch(url, { next: { tags: ["products"] } });

// To purge:
import { revalidateTag } from "next/cache";
revalidateTag("products");

Params & Query Handling

Q1.

How to access route params?

AnswerRoute params are available as a promise in the props of a Page component.

tsx
tsx
async function Page({ params }) {
  const { id } = await params;
}
Q2.

How to access query params?

AnswerQuery params (searchParams) are also available as a promise in Page props.

tsx
tsx
async function Page({ searchParams }) {
  const { category } = await searchParams;
}
Q3.

What is use()?

Answeruse() is a React hook used to unwrap promises (like params or searchParams) in Client Components.

tsx
tsx
const { id } = use(params);

Coding Questions

Q1.

Build a dynamic blog page

AnswerDemonstrates fetching data based on a dynamic slug.

tsx
tsx
async function Page({ params }) {
  const { id } = await params;
  const res = 
   await fetch(`https://api.com/blog/${id}`);
  const data = await res.json();

  return <div>{data.title}</div>;
}
Q2.

Fix hydration mismatch for dynamic content

AnswerUse useEffect to ensure dynamic client-only data (like timestamps) is only rendered after hydration.

tsx
tsx
"use client";

function Time() {
  const [time, setTime] = useState(null);
  useEffect(() => {
    setTime(new Date().toString());
  }, []);

  return <p>{time}</p>;
}

Advanced System Design

Q1.

How does Next.js improve performance?

AnswerVia Server Components (reduced JS), Automatic Code Splitting, Image/Font Optimization, and sophisticated Edge Caching.

Q2.

Explain streaming in Next.js

AnswerStreaming allows you to break down the page's HTML into smaller chunks and progressively send them from the server to the client. This allows 'instant' loading of headers while slower data-heavy components load via Suspense.

Q3.

How to design caching for e-commerce?

AnswerProduct pages should use SSG/ISR for speed. Reviews should use ISR for periodic updates. The Cart and User Profile must use SSR/Client-side fetching for real-time personalization.

Framework Logic & Decisions

Q1.

Should we use Next.js for frontend only or backend?

AnswerNext.js is 'Frontend-first Fullstack'. While it can handle full backend logic (Route Handlers, Server Actions, DB connections), it's optimized for UI-adjacent logic. For heavy business logic, high-performance computing, or shared services, a dedicated backend (Go, Python, Java) is often preferred.

Q2.

Why do companies use Next.js for frontend only, not backend?

Answer1. Separation of Concerns: Decoupling UI from business logic. 2. Scalability: Microservices allow scaling a Go backend independently of the Next.js frontend. 3. Legacy: Plugging a modern frontend into an existing enterprise API.

Q3.

Why use Next.js over React if it's a React framework?

AnswerBecause Next.js solves 'The Production Problem'. It provides SEO (SSR), performance (SSG), and file-system routing out of the box. Building these from scratch in pure React requires massive configuration and maintenance.

Q4.

Where should we use React but not Next.js?

Answer1. Internal tools/Admin panels where SEO is irrelevant. 2. Highly specific custom architectures where Next.js's opinionated routing is restrictive. 3. When you need absolute control over the build pipeline.

Q5.

What are the most important things for frontend development?

Answer1. Performance (Core Web Vitals). 2. Accessibility (a11y). 3. Responsiveness. 4. Consistent Design System. 5. Efficient State Management.

Rapid Fire Expectation

Middleware
Edge Runtime
Route Groups
loading.js
error.js
Parallel Routes
Intercepting Routes

Expect these quick-hit questions to test your breadth of the v15 API surface area.

Back to API
End of Module