Skip to content
Data & CachingChapter 14 / 34Intermediate5 min read

Data Fetching

Next.js data fetching in Server Components with async/await, fetch, databases and Suspense, plus the Next.js 16 rules you need to know.

On this page

1. What is data fetching?

In the App Router, every component is a Server Component by default. A Server Component can be async, so you can write await fetch() or await db.query() directly. You do not need useEffect or any loading state workaround.

Remember one important rule in Next.js 16: fetch is not cached by default. Every request gets fresh data. If you want caching, you opt in yourself (with "use cache").

2. Why does it matter?

In older React apps, data was fetched in the browser. The page arrived empty first, then a spinner, then the data. This hurt SEO and risked exposing API keys.

Client side fetching (the old way)Server Component fetching
Empty HTML first, then dataHTML arrives with the data
useEffect and useState boilerplatePlain async/await
API key can reach the browserSecrets stay on the server
Every client sends its own requestThe server is close to the database, so it is fast
Weak SEOSearch engines get the full content

3. Where is it used?

Use caseWhere the data comes from
Blog listfetch from a CMS API
Product pageA Prisma or Drizzle query to the database
DashboardUser specific data, using cookies
Weather widgetA third party API, fresh on every request
Search resultsA query based on searchParams

4. How does it work?

A request arrives, the Server Component runs on the server, the data is awaited, and the finished HTML is streamed to the browser.

Data fetching flow on the server
Browser request
Next.js server
async Server Component
await fetch or database query
HTML + RSC payload
UI in the browser

If a component needs slow data, wrap it in <Suspense>. The rest of the page shows immediately and the slow part is streamed in later.

5. Code example

Example 1: fetch in a Server Component

tsx
type Post = { id: number; title: string };

export default async function PostsPage() {
  const res = await fetch("https://api.example.com/posts");
  const posts: Post[] = await res.json();

  return (
    <ul>
      {posts.map((post) => (
        <li key={post.id}>{post.title}</li>
      ))}
    </ul>
  );
}

Example 2: streaming with Suspense and parallel fetching

tsx
import { Suspense } from "react";

async function getUser(id: string) {
  const res = await fetch(`https://api.example.com/users/${id}`);
  return res.json();
}

async function getOrders(id: string) {
  const res = await fetch(`https://api.example.com/users/${id}/orders`);
  return res.json();
}

async function Orders({ userId }: { userId: string }) {
  const [user, orders] = await Promise.all([getUser(userId), getOrders(userId)]);

  return (
    <section>
      <h2>Orders for {user.name}</h2>
      <p>Total orders: {orders.length}</p>
    </section>
  );
}

export default async function Page({ params }: PageProps<"/users/[id]">) {
  const { id } = await params;

  return (
    <main>
      <h1>User profile</h1>
      <Suspense fallback={<p>Loading orders...</p>}>
        <Orders userId={id} />
      </Suspense>
    </main>
  );
}

How does the code work?

PartMeaning
async function PostsPageA Server Component that can await directly
await fetch(...)Fresh data on every request, no cache by default
Promise.all([...])Both requests run together, so there is no waterfall
await paramsIn Next.js 16, params is a Promise
<Suspense fallback>The fallback shows until the orders arrive, and the rest of the page renders immediately

Interview tip

If you are asked "Is fetch cached in Next.js 16?", the answer is: No, it runs on every request by default. For caching, you use the "use cache" directive with cacheComponents: true.

6. Common mistakes

Mistake: Fetching data with useEffect in a Server Component

Why? Hooks do not run in a Server Component, and client fetching hurts both SEO and speed.

Better: Make the component async and write await fetch or a database query directly.

Mistake: Creating a waterfall by awaiting one after another

Why? Each request waits for the previous one, and the page becomes very slow.

Better: Run independent requests together inside Promise.all.

Mistake: Assuming fetch caches itself

Why? In Next.js 16, fetch is uncached by default. The old Next.js 14 behavior is gone.

Better: If you need caching, use the use cache directive and cacheLife.

Mistake: Blocking the whole page because of one slow component

Why? The user sees nothing until the slow data arrives.

Better: Wrap the slow component in Suspense so the rest of the UI streams first.

7. What to learn before and after

Final quick revision

PointDetail
Where to fetchIn Server Components, with async/await
Default cachingfetch is not cached by default
Parallel requestsPromise.all
Slow dataStream it inside <Suspense>
Route paramsawait params