01 / 06

How do we fetch data in server component?

Difficulty: 5/10
Server Components, Data Fetching, Next.js Caching
This example demonstrates a basic server-side data fetch using the fetch API in an asynchronous React Server Component.

Scenario Questions

0-2 years experience

  1. 1You need to display a list of products in a Next.js server component. How would you fetch the product data inside that component?
  2. 2If you forget to add `export const dynamic = 'force-static'` and try to fetch data in a server component, what error or behavior would you see?

2-5 years experience

  1. 1We have a page that shows user profile data using a server component, but the API sometimes returns a 500 error. How would you handle the error in the component to avoid breaking the whole page?
  2. 2Explain why using `fetch` with `{ cache: 'no-store' }` inside a server component might be necessary for a real‑time dashboard, and what trade‑offs it introduces.

5-8 years experience

  1. 1Our application needs to render a large list of items server‑side while keeping response times low. How would you design the data fetching in server components, considering streaming, pagination, and caching?
  2. 2We are migrating a legacy client‑side data fetching pattern to Next.js server components. What architectural changes and potential pitfalls would you watch for, especially around authentication tokens and request headers?

8+ years experience

  1. 1At scale, multiple teams build server components that all call the same internal API. How would you standardize data fetching across teams to ensure consistency, observability, and optimal caching?
  2. 2If we need to support incremental static regeneration (ISR) for a server component that fetches data from a third‑party API with rate limits, how would you design the fetching strategy to respect limits while keeping pages fresh?

Follow-up Questions

  • Can you sketch a minimal code example of the fetch call inside a server component?
  • What would you monitor in production to ensure the data fetching remains healthy?
  • How does this approach affect SEO and initial page load time?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.