intermediate
Data fetching on the server
Fetch near the data source, control cache behavior, avoid waterfalls, and keep request-only details server-side.
Fetch near the data source in Server Components or route handlers. Use `fetch` with Next.js cache options (`cache`, `next.revalidate`, `next.tags`) or mark routes dynamic when reads must be per-request.
Parallelize independent requests with `Promise.all` to avoid waterfalls. Request memoization deduplicates identical fetches in one render pass.
export default async function Page() {
const [user, posts] = await Promise.all([getUser(), getPosts()]);
return <Feed user={user} posts={posts} />;
}
On interviews: explain cache defaults, when to use `no-store`, and how tags connect to revalidation.
Common pitfalls: sequential awaits for unrelated data, caching personalized responses, and client refetch duplicating server work.
The trade-off is aggressive caching versus correctness for auth-scoped data.
Checklist:
- Parallelize independent server fetches.
- Set cache or dynamic per data sensitivity.
- Tag cache entries tied to mutations.
- Keep request-only headers server-side.