ThisCalculator

Everyday

Next.js Server Component Fetching: Is It Slower?

Updated · Standard formula, shown below

Average pace 5.00 min/km
Average speed
12.00 km/h
Result
Finish time
50 min
You entered
Distance
10 km
You entered

Next.js Server Components can fetch data slower than necessary if you don’t use the right caching and revalidation strategies, but with proper configuration they are typically faster than client-side fetching. This article explains how server-side data fetching works in Next.js, why it can be slow, and how to optimize it for your specific use case.

Formula

The calculator above computes your average pace and speed for a run or ride. The formulas are:

  • Pace = Finish time (minutes) ÷ Distance (km)
  • Speed = Distance (km) ÷ (Finish time (minutes) ÷ 60)

Where:

  • t = finish time in minutes
  • d = distance in kilometers
  • Pace is in minutes per kilometer (min/km)
  • Speed is in kilometers per hour (km/h)

Worked Example

Using the default values: finish time = 50 minutes, distance = 10 km.

  1. Pace = 50 ÷ 10 = 5.0 min/km
  2. Speed = 10 ÷ (50 ÷ 60) = 10 ÷ 0.8333 = 12.0 km/h

The calculator returns a pace of 5.0 min/km and a speed of 12.0 km/h, matching the example.

Why Server Components Fetch Data

Server Components run on the server, so they can fetch data directly from a database or API without exposing credentials to the browser. This reduces the number of round trips and can improve performance because the server is closer to the data source. However, if you fetch data inside a Server Component without caching, every request triggers a new fetch, which can be slower than necessary.

The key is that Next.js caches fetch requests by default in Server Components, but only if you use the fetch API. If you use a database client directly (like Prisma or an ORM), you must implement caching yourself. Many developers unknowingly disable caching by setting cache: 'no-store' or using dynamic functions like cookies() or headers(), which forces the component to be dynamic and re-fetch on every request.

How Caching Works in Server Components

Next.js uses a static/dynamic rendering model. By default, a Server Component is static unless it uses dynamic functions. When you use fetch, Next.js applies its built-in cache (the Data Cache) and stores the response. On subsequent requests, it reuses the cached data unless you specify revalidation.

Revalidation can be time-based with next: { revalidate: 60 } (seconds) or on-demand using revalidatePath() or revalidateTag(). If you need real-time data, you can set cache: 'no-store', but this disables caching entirely and makes every request hit the origin, which is slower.

For database queries, you can use React’s cache() function to memoize requests within a single render, but that doesn’t persist across requests. For cross-request caching, you need a separate solution like a key-value store or a custom cache layer.

Common Mistakes That Slow Down Fetching

  • Using cache: 'no-store' everywhere – forces a fresh fetch on every request, negating the benefits of server-side caching.
  • Calling cookies() or headers() in a component that doesn’t need them – makes the entire route dynamic, disabling static optimization.
  • Fetching data in a child component instead of a parent – each component fetches its own data, leading to duplicate requests.
  • Not using Promise.all for parallel fetches – sequential awaits increase total latency.
  • Ignoring the next option for revalidation – without it, data may become stale, but you might be using no-store out of fear of staleness.

How to Optimize Server Component Fetching

  1. Use fetch with default caching – it caches automatically and supports revalidation.
  2. Set appropriate revalidation intervals – for data that changes infrequently, use revalidate: 3600 (1 hour) or longer.
  3. Use revalidateTag for on-demand updates – after a mutation, call revalidateTag('posts') to refresh only that data.
  4. Fetch in the parent component and pass props down – avoids duplicate requests.
  5. Use Promise.all for independent fetches – reduces total wait time.
  6. Avoid dynamic functions unless necessary – if you need cookies, consider reading them in a client component or using middleware.

Comparing Server vs. Client Fetching

Client-side fetching (in useEffect or with SWR/React Query) runs after the page loads, showing a loading state. Server-side fetching happens before the page is sent, so the HTML includes the data, which is better for SEO and perceived performance. However, if you need real-time updates or user-specific data, client-side may be simpler.

Server Components are not inherently slower; they are slower only when misconfigured. A well-optimized server fetch can be faster than a client fetch because it avoids an extra round trip and can leverage edge caching.

Costs and Trade-offs

Server fetching uses server resources (CPU, memory, bandwidth) for every request, whereas client fetching offloads that to the user’s browser. With caching, server fetches are cheap because they hit the cache. Without caching, you pay the full cost on every request, which can be expensive at scale.

Another trade-off is staleness: cached data may be outdated. You must balance freshness with performance. For highly dynamic data (e.g., stock prices), you might need no-store, but for most content, revalidation is sufficient.

Frequently Asked Questions

Why is my Server Component fetching data on every request?

Because you’re using cache: 'no-store', or you’re using a dynamic function like cookies() or headers() that forces dynamic rendering. Remove those and use default caching or revalidation.

How do I cache database queries in Server Components?

Use a library like unstable_cache (from Next.js) or implement your own cache layer with Redis or in-memory store. The fetch API caching does not apply to direct database calls.

Is it faster to fetch data in a Server Component or a Client Component?

For initial page load, Server Components are faster because data is included in the HTML. For subsequent updates, Client Components with SWR or React Query can be faster because they can update without a full page reload.

How do I revalidate data after a form submission?

Call revalidatePath('/path') or revalidateTag('tag') in a Server Action or route handler after the mutation. This will purge the cache and trigger a new fetch on the next request.

Does using next: { revalidate: 60 } slow down my site?

No, it only invalidates the cache after 60 seconds. The first request after that period will fetch fresh data, but subsequent requests within the window are served from cache. The impact is minimal.

Can I use fetch with a database?

No, fetch is for HTTP requests. For databases, you need a database client. You can wrap your database query in a function and use unstable_cache to cache the result.

Related

Formula used
in t | Finish time | min | 50 | 0
in d | Distance | km | 10 | 0
out pace | Average pace | min/km | t / d | 2
out speed | Average speed | km/h | d / (t / 60) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.