Next.js Developer interview question · Most asked
How does data fetching work in the App Router?
Summary
Server Components can be async and fetch data directly with fetch or any database/ORM client. Next.js adds caching and revalidation options on top: fetch(url, { next: { revalidate: 60, tags: ['posts'] } }), segment-level export const revalidate, and (in newer versions) the 'use cache' directive.
Longer Answer
Fetch data where it's needed: identical fetch calls during one render are deduplicated (request memoization), and you can wrap non-fetch data functions in React's cache() for the same effect. Avoid waterfalls by starting independent requests in parallel (Promise.all) and streaming slower parts behind <Suspense>. Client-side fetching (SWR, TanStack Query) is still useful for highly interactive or user-specific live data.
Code Example
export default async function Dashboard() {
const [user, stats] = await Promise.all([
getUser(), // React cache()-wrapped DB call
fetch("https://api.example.com/stats", { next: { revalidate: 60, tags: ["stats"] } }).then((r) => r.json()),
]);
return <Overview user={user} stats={stats} />;
}
Key Points
- Async Server Components fetch directly
- Request memoization dedupes identical fetches
revalidateand tags control freshness- Parallelize with
Promise.all; stream with Suspense
More most-asked Next.js Developer questions
- How did caching defaults change in Next.js 15?
- Explain SSR, SSG, ISR and CSR in Next.js.
- What happens, step by step, when a request reaches a Next.js App Router application?
- What is Next.js and what problems does it solve on top of React?
- What are the differences between the App Router and the Pages Router?
- What is the difference between Server Components and Client Components?
- Explain the App Router file conventions: page, layout, loading, error, not-found, template and route.
- What are Server Actions and how do you use them for mutations?