Skip to content
Learn Netverks

Lesson

Step 18/36 50% through track

fetch-server

Server-side data fetching

Last reviewed May 28, 2026 Content v20260528
Track mode
client_nextjs
Means
In-browser Next.js (client components)
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Server-side data fetching: the concepts, APIs, and habits you need before advancing in Next.js.

Data fetching patterns appear in every dashboard; loading and error states are not optional polish.

You will apply Server-side data fetching in contexts like: Dashboards, live tables, and detail pages backed by REST or GraphQL APIs.

Write TSX for Client Components, click Run—React 18 CDN + in-browser TSX compile; use client/server lessons explain App Router concepts; mountApp renders interactive UI; printOutput feeds the terminal. Also read server-component lessons carefully—SSR runs in a real Next project, not in the iframe.

When you can explain the previous lesson's ideas without copying starter code.

In Server Components, data fetching is often just async code in the component—no useEffect, no loading spinner boilerplate on the client for the initial HTML.

Fetch in a page

export default async function Page() {
  const res = await fetch('https://api.example.com/posts', {
    next: { revalidate: 60 },
  });
  const posts = await res.json();
  return <PostList posts={posts} />;
}

Direct database access

With an ORM (Prisma, Drizzle), call the database directly in the Server Component—no separate REST layer required for internal data.

Parallel fetching

const [user, orders] = await Promise.all([
  getUser(id),
  getOrders(id),
]);

Avoid sequential awaits for independent queries—they add latency.

Important interview questions and answers

  1. Q: fetch in Server Component vs useEffect?
    A: Server fetch runs once per request/build on the server; useEffect runs client-side after hydration—bad for SEO-critical initial data.
  2. Q: Can you use fetch cache options?
    A: Yes—cache, next.revalidate, and tags integrate with Next.js Data Cache.

Self-check

  1. Why is async/await natural in Server Components?
  2. When would you still fetch on the client?

Interview prep

Why fetch in Server Components?

Data arrives in initial HTML for SEO and fast first paint—no client loading spinner for critical content; secrets stay on the server.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Where fetch runs?
  • Waterfall risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump