Skip to content
fearchitect
Network & Infrastructure

Edge Computing & Rendering

Run code at CDN PoPs to cut latency before origin is hit.

By Abas TurabliReviewed

Summary

Edge compute (Cloudflare Workers, Vercel Edge Functions) executes JavaScript in V8 isolates at CDN points of presence, often 10–50 ms from the user. The model cuts round-trip time for auth, personalisation, and SSR — but isolates lack Node.js APIs and cold data must still travel to the origin.

Jump to the interview angle

Edge compute runs JavaScript (and WASM) in V8 isolates — not Node.js processes — at CDN points of presence (PoPs) worldwide. Isolates start in under 5 ms with no cold-start penalty, but they trade Node APIs (no fs, no native bindings) for near-zero spin-up cost.

Vercel calls its layer Edge Functions (deployed via export const runtime = "edge") and Routing Middleware (the middleware.ts file that runs before every request). Cloudflare calls the equivalent a Worker. Both give you Request/Response (the Fetch API), crypto, streaming, and geo headers — not the full Node standard library.

Edge vs. origin runtime

DimensionEdge (V8 isolate)Origin (Node.js / container)
Cold start< 5 ms — isolates are shared50–500 ms for a fresh container
Latency to user10–50 ms — nearest PoP100–400 ms — single region
Runtime APIsFetch, Web Crypto, Streams, KVFull Node.js + native modules
CPU time limit50 ms (Vercel) / 30 s (CF)No hard cap per request
Database accessRound-trip to origin regionLocal — same VPC or loopback
Best forAuth, personalisation, A/B, geoHeavy DB queries, file I/O

Routing Middleware: geolocation redirect

Vercel Middleware runs at the edge before a request reaches any page or API. The geo object on NextRequest is populated by Vercel's infrastructure — no third-party lookup needed.

middleware.ts — country-based redirectts
// middleware.ts (project root — not inside /app or /pages)
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
  const country = request.geo?.country ?? "US";

  // Personalise: send EU users to /eu landing page
  if (country === "DE" || country === "FR") {
    const url = request.nextUrl.clone();
    url.pathname = "/eu" + url.pathname;
    return NextResponse.rewrite(url);
  }

  return NextResponse.next();
}

export const config = {
  // Run only on marketing pages, skip _next assets
  matcher: ["/((?!_next|favicon.ico).*)"],
};

No origin hit for the redirect decision. request.geo is injected by Vercel's edge layer. Keep middleware under 1 MB and avoid DB calls here — use KV or a cookie for pre-resolved state.

Edge reads session from KV; only a cache miss reaches the origin region.

When edge helps — and when it does not

Pros

  • Geolocation and A/B decisions in < 5 ms with no origin round-trip.
  • Auth token verification (JWT, signed cookie) is pure CPU — ideal for isolates.
  • Streaming edge SSR starts sending HTML bytes before origin data returns.
  • No cold-start tax: isolates are always warm at busy PoPs.

Cons

  • Every DB query adds a cross-region round-trip, erasing latency gains.
  • No Node.js native modules — drivers for Postgres, Redis need HTTP/WebSocket wrappers.
  • CPU time limits (50 ms on Vercel) block long-running or CPU-heavy work.
  • Debugging is harder — no local parity for the real PoP network topology.
  • Stateful session stores must be edge-replicated (e.g., Upstash Redis) to avoid centrality.

The data locality test

Before moving logic to the edge, ask: where does the data live? If it is in a single-region Postgres, the edge function must still phone home — you gain nothing on latency and lose Node.js APIs. Edge wins when data is in an edge KV store, a cookie, or a short-TTL CDN cache already at the PoP.

Interview angle

Interviewers ask when edge SSR helps vs hurts. Strong answers name the V8 isolate constraint, explain that latency wins only when origin data is cached or co-located, and call out geolocation as a free input.

Soundbite: "Edge is fast only when the data is already at the edge — otherwise you just moved the round-trip."

Key terms

V8 isolate
A sandboxed JS execution context inside a single V8 process; no OS process overhead, starts in microseconds.
Edge Function
Vercel's name for a serverless function running in V8 isolates at CDN PoPs, using the Web API surface.
Routing Middleware
Vercel's `middleware.ts` — runs at the edge on every matched request before any page handler.
PoP
Point of Presence: a CDN datacenter geographically close to users where edge code runs.
Edge KV
A globally replicated key-value store (e.g., Cloudflare KV, Vercel KV) readable from edge code without a round-trip to the origin region.

Further reading

Search fearchitect

Jump to a topic, mode, or action.