Next.jsMedium

What is edge rendering and when should you use it?

Edge rendering means running server code in data centers close to the user, typically on lightweight runtimes such as V8 isolates, to reduce latency. In Next.js it meant setting runtime = "edge" on routes. That option is deprecated now; the recommended way to get edge-like speed is to serve prerendered static shells from a CDN and stream the dynamic parts from Node.js functions near your data.

The original promise

  • Low cold-start overhead and execution near the user.
  • Good for simple personalization: geo, A/B tests, auth redirects.

Why it fell out of favor

  • Data gravity: most pages query a database in one region. Rendering far from it adds a round-trip per query, often making pages slower.
  • API limits: no fs, no native modules, limited npm compatibility and code size.
  • No ISR on the Edge runtime.
  • Node.js cold starts improved significantly on modern platforms.

What Next.js recommends in 16

  • Remove runtime = "edge" from pages and Route Handlers (deprecated, and unsupported with Cache Components).
  • Use Partial Prerendering: the static shell is served from the CDN edge instantly, which is the "edge" part users feel, and request-time parts stream from the origin.
  • Use proxy.ts for request-time routing logic like geo redirects. Some platforms deploy it close to users.
  • Use preferredRegion to run functions near your database.
  • Cache aggressively with "use cache" and cacheLife.

When edge compute still helps

Pure request rewriting, header manipulation, bot filtering and redirects that need no database. These belong in Proxy or your CDN's own edge features.

Code example

tsx
1// Before: edge rendering per route (deprecated)
2// export const runtime = "edge";
3
4// Now: static shell from the CDN + streamed dynamic part from a region near the DB
5// app/store/page.tsx
6import { Suspense } from "react";
7import { cookies } from "next/headers";
8import { cacheLife } from "next/cache";
9
10async function Catalog() {
11 "use cache";
12 cacheLife("hours");
13 const items = await fetch("https://api.example.com/items").then((r) => r.json());
14 return <ul>{items.map((i: { id: string; name: string }) => <li key={i.id}>{i.name}</li>)}</ul>;
15}
16
17async function Cart() {
18 const id = (await cookies()).get("cart")?.value;
19 const cart = await fetch(`https://api.example.com/cart/${id}`).then((r) => r.json());
20 return <p>{cart.count} items</p>;
21}
22
23export default function Store() {
24 return (
25 <>
26 <Catalog />
27 <Suspense fallback={<p>Cart…</p>}><Cart /></Suspense>
28 </>
29 );
30}
31
32// next.config or segment: run functions near the database
33// export const preferredRegion = "fra1";

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app