Skip to content
Now accepting new projects — limited slots available. Get started →
Architecture · Updated Jul 30, 2026

What is Edge Runtime?

Edge Runtime is an execution environment that runs server-side code at CDN points of presence closest to the user.

What is Edge Runtime?

Edge Runtime is a lightweight JavaScript execution environment that runs server-side code at CDN points of presence (PoPs) geographically close to the end user, rather than in a single origin region. Unlike traditional serverless functions that spin up in one or a few data center regions, edge runtimes distribute compute across dozens or hundreds of locations worldwide. Cloudflare Workers (launched 2017) popularized the model, and Vercel introduced its Edge Runtime for Next.js middleware in v12 (October 2021). These environments use a V8 isolate model instead of full Node.js containers, which means cold starts under 5ms but a restricted API surface — no native Node.js modules like fs, net, or child_process.

I've shipped edge runtimes on 50+ projects. They're good for authentication checks, geolocation-based routing, A/B testing, and personalized cache keys where sub-50ms TTFB matters. Not much else.

How it works

Edge runtimes use V8 isolates — the same engine that powers Chrome — rather than full OS-level containers. Each incoming request spins up an isolate (or reuses a warm one) inside a shared process. This is fundamentally different from AWS Lambda's container model.

The execution model is closer to the Web Workers API than to Node.js. You get fetch, Request, Response, URL, TextEncoder, crypto.subtle, and a handful of other Web Platform APIs. You don't get the full Node.js standard library.

Here's what a basic edge function looks like in Next.js (App Router, as of Next.js 15):

// app/api/geo/route.ts
export const runtime = 'edge';

export async function GET(request: Request) {
  const country = request.headers.get('x-vercel-ip-country') || 'US';
  return Response.json({
    message: `Serving from the edge, detected country: ${country}`,
    timestamp: Date.now(),
  });
}

The key line is export const runtime = 'edge'. That single declaration tells the framework to bundle and deploy this route to edge locations instead of a regional Node.js serverless function.

Under the hood, providers like Cloudflare (300+ PoPs), Vercel (via Cloudflare's network), and Deno Deploy (35+ regions) receive the request at the nearest PoP, execute your code there, and return the response — often achieving TTFB under 50ms globally. The trade-off is strict memory limits (typically 128MB), CPU time limits (usually 10-50ms of wall-clock CPU), and no persistent filesystem.

When to use it

Edge Runtime is a precision tool, not a default. Here's when it actually makes sense:

Use it when:

  • You need to modify requests/responses before they hit the origin (auth token validation, redirects, header injection)
  • Geolocation-based logic like currency/language selection or regional compliance blocking
  • A/B test assignment where you need to set cookies before the page renders
  • Personalized cache key generation to get the best of CDN caching + personalization
  • Lightweight API endpoints that return small JSON payloads from edge-compatible datastores (e.g., Upstash Redis, Turso, Cloudflare D1)

Don't use it when:

  • You need native Node.js APIs (file system, TCP sockets, heavy crypto)
  • Your function calls a database in a single region anyway — you'll add latency by running compute far from data
  • CPU-intensive work like image processing or PDF generation exceeds edge CPU limits
  • You're importing large npm packages that aren't edge-compatible

The single-region-database problem is the most common mistake I see. Running code at the edge that then makes a 200ms round-trip to a database in us-east-1 defeats the purpose entirely. You've just added network hops for nothing.

Edge Runtime vs alternatives

Feature Edge Runtime Regional Serverless (Lambda/Cloud Functions) Traditional Server
Cold start < 5ms (V8 isolates) 100-500ms (containers) None (always warm)
Global distribution 30-300+ PoPs 1-5 regions typically 1-2 regions typically
Node.js compatibility Partial (Web APIs only) Full Full
Max execution time 10-50ms CPU (varies) 15 min (Lambda) Unlimited
Max memory ~128MB Up to 10GB (Lambda) Server RAM
Persistent connections Limited/none Yes Yes
Cost model Per-request, very cheap Per-request + duration Fixed infra cost

My preferred stack: Edge Runtime for middleware and lightweight API routes in Next.js, regional serverless for anything that talks to a database, and long-running servers only when I need WebSockets or heavy background processing.

Real-world example

On a recent e-commerce project built with Next.js 15, I used Vercel Edge Middleware to handle three things before any page rendered: (1) detect the visitor's country via the x-vercel-ip-country header and rewrite to the correct locale, (2) check for an existing A/B test cookie and assign a variant if missing, and (3) validate a JWT session token against Upstash Redis to decide whether to show authenticated or guest pricing.

All three operations completed in under 12ms p95 globally. The same logic running as a regional serverless function in us-east-1 had a p95 of 180ms for users in Asia-Pacific. That latency difference directly improved Largest Contentful Paint by roughly 150ms for international traffic — meaningful for both Core Web Vitals and conversion rates.

Frequently asked questions about Edge Runtime

Is Edge Runtime the same as serverless functions?
No. Serverless functions (like AWS Lambda or Vercel Serverless Functions) typically run in one or a few cloud regions using full Node.js containers with cold starts of 100-500ms. Edge Runtime runs at CDN edge locations worldwide using V8 isolates with cold starts under 5ms. The key difference is the execution model: edge uses a restricted Web API surface (no `fs`, `net`, `child_process`) in exchange for global distribution and near-zero cold starts. Think of edge runtime as a specialized subset of serverless — every edge function is serverless, but not every serverless function runs at the edge.
When did Edge Runtime become standard?
Cloudflare Workers launched in 2017 as the first major edge compute platform. The concept went mainstream in the JavaScript framework ecosystem when Next.js 12 introduced Edge Middleware in October 2021. Vercel formalized its Edge Runtime as an open-source package (`edge-runtime` on npm) in 2022. By 2023-2024, Deno Deploy, Fastly Compute, and Netlify Edge Functions all offered similar V8-isolate-based edge environments. The WinterTC (formerly WinterCG) group — now part of TC39 ecosystem efforts — has been working to standardize the minimum API surface across edge runtimes since 2022, though full interoperability is still a work in progress as of April 2026.
What's the alternative to Edge Runtime?
The primary alternative is regional serverless functions — AWS Lambda, Google Cloud Functions, or Vercel Serverless Functions running full Node.js in a specific region. These give you the complete Node.js API surface and longer execution times (up to 15 minutes on Lambda) at the cost of higher cold starts and single-region latency. For workloads that primarily talk to a single-region database, regional serverless is often the better choice because it keeps compute close to data. Another alternative is edge caching (CDN cache) for responses that don't need per-request compute — sometimes a stale-while-revalidate cache strategy outperforms edge compute entirely.
Can Edge Runtime connect to a traditional database?
Technically yes, but it's usually a bad idea. Most traditional databases (PostgreSQL, MySQL) live in a single region and use TCP connections. Edge runtimes don't support persistent TCP connections natively, and making a round-trip from an edge location in Tokyo to a database in Virginia adds 150-200ms of network latency. The workaround is using edge-compatible databases: Cloudflare D1, Turso (distributed SQLite based on libSQL), PlanetScale with their HTTP-based driver, or Upstash Redis — all designed to work over HTTP/fetch and often replicated to multiple regions. If your data can't move to the edge, your compute probably shouldn't either.
Get in touch

Let's build
something together.

Whether it's a migration, a new build, or an SEO challenge — the Social Animal team would love to hear from you.

Get in touch →