ReactMedium
What is Edge Rendering?
Edge rendering means running server rendering in lightweight runtimes deployed to many locations close to users (CDN edge networks, V8 isolates), instead of in one central region. It reduces network latency for the first byte, but edge runtimes have limited APIs, and if your data lives in one region, every query travels back to it, which can make pages slower.
Benefits
- Low latency for users far from your main region.
- Fast cold starts in isolate-based runtimes.
- Good for personalization based on request data only (geo, cookies, A/B buckets).
Limitations
- Web APIs only: no
fs, no native Node.js modules, limited npm compatibility. - Small code size limits and execution time limits.
- Data gravity: a database in one region adds a round-trip per query from each edge location.
How the industry evolved
- Next.js deprecated
runtime = "edge"for pages and Route Handlers in recent versions; its Proxy (formerly middleware) runs on Node.js since Next.js 16. The recommended pattern is a static shell served from the CDN edge plus dynamic content streamed from functions near the database. - Platforms like Cloudflare Workers still run full apps at the edge, often paired with globally replicated or edge-local data (D1, KV, Durable Objects, read replicas).
When to use it
- Request rewriting, redirects, auth checks on signed cookies, feature flags, bot filtering.
- Apps whose data is also distributed globally.
Interview framing
Explain the latency trade-off: move compute to the user only if the data can follow; otherwise cache at the edge and compute near the data.
Code example
tsx
1// Cloudflare Worker-style edge handler: personalization from request data only2export default {3 async fetch(request: Request): Promise<Response> {4 const url = new URL(request.url);5 const country = request.headers.get("cf-ipcountry") ?? "US";67 // Cheap decision at the edge: redirect to a regional storefront8 if (url.pathname === "/" && country === "IN") {9 return Response.redirect(new URL("/in", url), 302);10 }1112 // Serve cached HTML from the edge cache, fetch from origin on a miss13 const cache = (caches as unknown as { default: Cache }).default;14 const cached = await cache.match(request);15 if (cached) return cached;1617 const response = await fetch(`https://origin.example.com${url.pathname}`);18 const copy = new Response(response.body, response);19 copy.headers.set("Cache-Control", "public, s-maxage=300");20 await cache.put(request, copy.clone());21 return copy;22 },23};
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 React set.