How does data fetching work in the Next.js App Router?
IntermediateNext.js interview questionBy UIRound, updated 17 November 2026
Short answer
In the App Router, data is fetched inside components. A Server Component can be an async function that awaits fetch, a database query or any other server code, and the result is rendered to HTML and the React Server Component payload on the server. Slow parts are streamed behind <Suspense> or loading.js. Mutations go through Server Actions. Client-side fetching with a library such as SWR or TanStack Query is still used for interactive, frequently changing data.
Fetching in an async Server Component
There is no getServerSideProps or getStaticProps. The component that needs the data fetches it.
// app/products/[id]/page.tsx
import { notFound } from "next/navigation";
import { db } from "@/lib/db";
export default async function ProductPage({ params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const product = await db.product.findUnique({ where: { id } });
if (!product) notFound();
const res = await fetch(`https://reviews.example.com/products/${id}`);
const reviews: Review[] = await res.json();
return (
<>
<h1>{product.name}</h1>
<Reviews items={reviews} />
</>
);
}Because this code runs only on the server, the database client and any secrets never reach the browser. It still needs proper authorisation checks: a Server Component is not a security boundary by itself. Mark server-only modules with import "server-only" so an accidental import from a Client Component fails the build.
Two built-in helpers stop duplicate work within one render. Identical fetch calls are memoised automatically, so a layout and a page can both ask for the current user without a second request. For non-fetch data, wrap the function in React's cache(), which shares one result per request. This lets you fetch where the data is used instead of drilling props down from the top. The split between server and client code is covered in Server Components vs Client Components.
Caching, briefly
In current Next.js, fetch and database calls are not cached by default. With Cache Components enabled (the default for new apps created with create-next-app), you opt in with the 'use cache' directive plus cacheLife and cacheTag; uncached work must sit inside a <Suspense> boundary so the rest of the page can still be prerendered. Older apps without Cache Components use fetch options such as next: { revalidate: 60 } and segment exports such as export const revalidate. The full picture is in How does caching work in Next.js?.
Sequential vs parallel fetches
Each await pauses the component. Two independent awaits in a row form a waterfall: the second request starts only after the first finishes.
// Sequential: total time is artist + albums
const artist = await getArtist(username);
const albums = await getAlbums(username);
// Parallel: both start at once; total time is the slower of the two
const [artist, albums] = await Promise.all([getArtist(username), getAlbums(username)]);Keep a sequential fetch only when the second request truly needs the first result, such as fetching playlists by artist.id. Even then, you can render the first result immediately and put the dependent component behind <Suspense> so it streams in later. Use Promise.allSettled if one failure should not break the whole page.
Next.js also renders layouts and pages of a route in parallel, so a layout's fetch does not delay the page's fetch. When a component's data would only start loading after other blocking work, a preload function that calls the fetcher without await starts it early, and the memoised call later reuses it.
Streaming with Suspense and loading.js
Without streaming, the slowest query decides when the user sees anything. Streaming sends the page in chunks: the shell first, then each slow part as it resolves.
import { Suspense } from "react";
export default function Dashboard() {
return (
<>
<h1>Dashboard</h1>
<Suspense fallback={<p>Loading revenue...</p>}>
<Revenue /> {/* async Server Component */}
</Suspense>
<Suspense fallback={<p>Loading orders...</p>}>
<LatestOrders />
</Suspense>
</>
);
}A loading.tsx file does the same for a whole route segment: Next.js wraps the page in a Suspense boundary with that file as the fallback, and shows it instantly on navigation. Granular <Suspense> boundaries close to the slow data usually give a better result. Note that loading.tsx sits below the layout of its segment, so it cannot cover uncached data read in that layout. How these files nest is explained in layout, loading and error files.
You can also start a fetch in a Server Component without awaiting it, pass the promise to a Client Component, and read it there with React's use(). The Client Component suspends until the data arrives.
Mutations with Server Actions
Writes go through Server Actions: async functions marked 'use server', called from a form's action or from client code.
// app/products/actions.ts
"use server";
import { updateTag } from "next/cache";
export async function addReview(formData: FormData) {
const user = await requireUser(); // check auth in every action
await db.review.create({
data: { productId: String(formData.get("productId")), text: String(formData.get("text")), userId: user.id },
});
updateTag("reviews"); // expire cached reviews so the user sees their own write
}After the mutation, Next.js can return the updated UI in the same round trip. Invalidate cached data with updateTag, revalidateTag or revalidatePath, or call refresh() to rerender the current route. Server Actions are for writes. The client currently dispatches them one at a time, so do not use them to fetch data. Details and security rules are in What are Server Actions?.
Where client-side fetching still fits
Server fetching covers the first render. Fetch in the browser when the data depends on what the user does after the page has loaded:
- Search-as-you-type, filters and infinite scroll.
- Polling or live data, such as notifications or prices.
- Data private to the browser, such as something read from
localStorage.
Use SWR or TanStack Query in a Client Component, calling a Route Handler or an external API. A common pattern is to fetch the first page on the server and pass it as initial data to the client library, which then takes over. For trade-offs between these libraries and plain fetching, see the data fetching and caching guide.
Practise it
Build a Suspense-based data-loading example with streaming SSR boundaries and Reveal Suspense skeletons in order without popcorn loading practise streaming. Decide the server/client component boundary for a Next.js product page asks where each fetch belongs, Implement request deduplication for identical in-flight API calls shows how memoisation works, and Build a sign-up form with useActionState covers the mutation side. Fix a Next.js page that shows stale data ties it to caching.
Common follow-up questions
Should a Server Component call my own Route Handler?
Usually no. It already runs on the server, so calling /api/... adds an extra HTTP hop. Call the database or a shared data function directly. Route Handlers are for clients outside the React tree, such as mobile apps, webhooks and browser fetches.
Can a Client Component be async?
No. Only Server Components can be async. In a Client Component, read a promise passed from the server with use(), or use a client fetching library.
How do I pass data from a layout to its page?
You cannot pass props from a layout to children. Fetch the data again in the page; memoised fetch or React.cache makes the second call free within the same request.
Why is my whole page waiting for one slow query?
That query is awaited outside any Suspense boundary. Move it into its own async component and wrap it in <Suspense> with a fallback, so the rest of the page can render first.
Mistakes to avoid
Writing independent awaits one after another and creating a waterfall
Fetching in
useEffectfor data that could be fetched on the server for the first renderUsing Server Actions to read data
Forgetting authorisation checks in Server Actions, which are reachable by direct POST requests
Assuming
fetchresults are cached across requests by defaultIn current Next.js they are not unless you opt in.
Reading uncached data in a layout and expecting the segment's
loading.tsxto cover it
Sources
Practise it in code
Interviewers rarely stop at the definition. These questions open in an editor with tests.
- Build a Suspense-based data-loading example with streaming SSR boundariesHard75 min
- Decide the server/client component boundary for a Next.js product pageHard45 min
- Reveal Suspense skeletons in order without popcorn loading: nested boundaries and tail modesMedium40 min
- Build a sign-up form with
useActionState: field errors, kept values, pending and successMedium35 min - Implement request deduplication for identical in-flight API callsMedium35 min
- Fix a Next.js page that shows stale data, layer by layer through its cachesHard45 min