Edge Computing

Edge computing runs code and stores data close to where it's needed — at the network edge, in hundreds of locations near users — instead of in a handful of centralized cloud regions. When a request no longer travels across a continent to a distant data center and back, latency drops from hundreds of milliseconds to tens, and the experience feels instant.

The web-development flavor of edge computing exploded when CDNs — already operating a global network of points of presence to cache static assets — added the ability to run code at those locations. Suddenly the same infrastructure that served your images could execute logic milliseconds from the user: rewriting requests, personalizing responses, authenticating, and rendering. This page focuses on that modern edge — edge functions and edge platforms — while placing it in the broader edge-computing picture.

TL;DR

Quick Example

An edge function runs at the location nearest each visitor. Here one personalizes a response by the user's country — with no origin round-trip:

The same code is deployed to every edge location automatically; each request is served by the nearest one.

Core Concepts

Why Distance Is Latency

Network latency is bounded by physics — data travels at a finite speed through fiber. A round-trip from Sydney to a US-East data center is inherently ~200ms before any processing. Edge computing removes that distance: if the code runs at a point of presence in Sydney, the round-trip is a few milliseconds. For latency-sensitive interactions, where the compute runs dominates how fast the compute is.

The Edge Runtime Model

Edge functions don't run in traditional containers or VMs. They run in lightweight, fast-starting isolates (or WebAssembly sandboxes) that spin up in milliseconds — because a request could hit any of hundreds of locations, and you can't keep heavy runtimes warm everywhere. The tradeoffs of this model:

Edge Functions vs Central Serverless

Both are serverless, but they differ in where they run and what they can do:

They're complementary layers, not substitutes.

Use Cases and Anti-Patterns

Where Edge Shines

Where Edge Struggles

💡 Tip: The edge helps only when the data the code needs is also near the edge. Code at the edge calling a database across the world is often slower than central compute co-located with that database. Move data to the edge (edge KV, replicated stores) or keep data-heavy logic central.

Best Practices

Put the Fast, Distributed Layer at the Edge

Use the edge for the lightweight, latency-sensitive front layer — routing, auth, personalization, caching — and keep heavy or data-intensive work in central cloud. This hybrid split gets the latency win without fighting the edge's constraints.

Mind Data Gravity

Co-locate data with compute. If edge code depends on data, use edge-native stores (edge key-value, edge databases, replicated caches) so the data is near the code. Otherwise the request still pays the long trip — to the database instead of the origin.

Keep Functions Small and Stateless

Edge functions have tight CPU and memory budgets and are ephemeral. Write short, stateless handlers; push heavy processing and durable state elsewhere. Trim dependencies aggressively — edge bundles must be lean.

Target Web-Standard APIs

Edge runtimes implement web-standard APIs (Fetch, Request/Response, Web Crypto) rather than the full Node.js API. Write to that standard surface for portability across edge platforms and to avoid depending on Node built-ins that aren't there.

Measure Real User Latency

The edge's whole value is latency, so measure it from real users worldwide (RUM), not from one office. Verify the edge is actually reducing tail latency for distant users, and watch that data-access patterns aren't quietly reintroducing the round-trips you removed.

Common Mistakes

Running Data-Heavy Logic at the Edge

Assuming a Full Node.js Runtime

Importing a library that needs Node built-ins (fs, native modules, full Buffer semantics) into an edge function often fails at deploy or runtime. Check that dependencies target web-standard runtimes.

Using the Edge for Everything

Edge computing is a front-layer optimization, not a general compute platform. Forcing heavy, stateful, or database-bound workloads onto it fights its constraints. Keep those central and let the edge do what it's good at.

FAQ

What's the difference between edge computing and the cloud?

Traditional cloud runs your code in a few centralized regions; edge computing runs it in many locations close to users. The cloud offers full runtimes, big resources, and co-located databases; the edge offers minimal latency and global distribution with constrained resources. They're complementary — edge for the fast distributed layer, central cloud for heavy lifting and the source of truth.

How is an edge function different from a Lambda?

A central serverless function like Lambda runs in a specific region with a full runtime and generous resources but higher latency for distant users. An edge function runs at hundreds of locations at once with millisecond cold starts and minimal latency, but with a constrained CPU/memory budget, web-standard (not full Node.js) APIs, and no nearby database by default. Use each for what it's suited to.

When should I use edge computing?

When latency matters and the work is lightweight and distributable: request rewriting and routing, auth checks, geolocation and personalization, edge caching, and fast server-rendering close to users. Avoid it for heavy compute, large dependencies, or database-intensive work — those belong in central cloud.

Does running code at the edge always make things faster?

No. It only helps if the data the code needs is also near the edge. Edge code that makes several calls to a database in one distant region can be slower than central compute sitting next to that database — you've just moved the round-trips. This is "data gravity": co-locate data with compute, or keep data-heavy logic central.

What runs edge functions?

Platforms built on global CDN networks — Cloudflare Workers, Vercel Edge Functions, Fastly Compute, AWS CloudFront Functions/Lambda@Edge, Deno Deploy, and others. They use lightweight isolates or WebAssembly sandboxes for fast startup, and target web-standard APIs. See Cloudflare Workers.

Related Topics

References