Server and Client Components in Next.js · mid
Fetching data in Server Components without waterfalls
Server Components fetch data directly with await; start independent requests in parallel (or pass promises down) to avoid waterfalls, dedupe repeated reads in one render with React.cache, and use a client library only for interactive or live data.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Async Server Components can
awaitthe database or an API directly; nouseEffect, no API route in between. - Sequential
awaits for independent data create a waterfall:await getUser(); await getPosts();takes the sum of both. UsePromise.all, or start both promises and await later. - Better streaming: start the fetch in the parent, pass the promise to a child inside
<Suspense>, and await (oruse()) it there, so the rest renders first. React.cache(fn)dedupes calls with the same arguments within one render pass (for examplegetPost(slug)in bothgenerateMetadataand the page). It does nothing in Server Actions and Route Handlers (not a render pass), and it is not a cross-request cache.- Preload pattern: call
void getItem(id)early so the request starts before other blocking work. - With Cache Components, uncached data must be inside
<Suspense>or cached with"use cache", otherwise the dev overlay reports a blocking route. - Do not call your own Route Handler from a Server Component; call the shared server function directly.
- Client-side fetching (TanStack Query, SWR) still fits polling, infinite scroll, data that changes from user interaction, and offline.
The red pen
Common traps: mistake → fix
Mistake: "Fetch in useEffect in the App Router"
Fix: slower and ships more JS; fetch on the server unless it is truly client-driven.
Mistake: "
React.cachecaches across requests"Fix: one render pass only.
Mistake: "Awaiting everything in the page is fine"
Fix: it blocks streaming and creates waterfalls.
Easy to hard
Questions interviewers ask, easy to hard
- How do you fetch data in the App Router?
- This page awaits user, then orders, then recommendations. What is wrong?
- How do you share one request between
generateMetadataand the page? - When do you still use TanStack Query in a Next.js app?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.