Skip to the page

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.

The notes

What you must know

  • Async Server Components can await the database or an API directly; no useEffect, no API route in between.
  • Sequential awaits for independent data create a waterfall: await getUser(); await getPosts(); takes the sum of both. Use Promise.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 (or use()) it there, so the rest renders first.
  • React.cache(fn) dedupes calls with the same arguments within one render pass (for example getPost(slug) in both generateMetadata and 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.cache caches 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

  1. How do you fetch data in the App Router?
  2. This page awaits user, then orders, then recommendations. What is wrong?
  3. How do you share one request between generateMetadata and the page?
  4. When do you still use TanStack Query in a Next.js app?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview