What is Edge Computing?
Moving code closer to the user: Understanding Edge networks, Cloudflare Workers, and Vercel Edge.
In traditional web architecture, a user in Tokyo making an API request might wait hundreds of milliseconds as their request travels under the ocean to a server in Virginia, waits for a database query to resolve, and travels all the way back. This geographic distance imposes a hard physical limit on web performance: the speed of light.
Edge computing aims to solve this by moving computation—the actual execution of backend code—out of centralized data centers and into localized servers placed physically close to the user.
The Evolution: Origin -> CDN -> Edge
To understand the Edge, it helps to see how web architecture has evolved.
- The Origin Server: All code and assets live on a single server (e.g., AWS us-east-1). Every user globally hits this server. High latency for global users.
- The CDN (Content Delivery Network): Static assets (images, CSS, JS) are cached at hundreds of points of presence (PoPs) globally. A user in Tokyo gets the image from a Tokyo server. However, dynamic API requests still must go back to the origin server in Virginia.
- Edge Computing: Instead of just caching static files, the PoPs run compute engines. The dynamic API request is intercepted and processed in Tokyo.
How Edge Functions Work (V8 Isolates)
If you've used AWS Lambda (Serverless), you know it can take 1-3 seconds for a function to spin up if it hasn't been used recently (a "Cold Start"). This happens because AWS is literally booting up a lightweight virtual machine and a Node.js process.
Edge platforms like Cloudflare Workers and Vercel Edge cannot afford cold starts. Instead of booting up VMs or Node.js processes, they use V8 Isolates.
V8 is the JavaScript engine that powers Google Chrome. An "isolate" is an independent instance of the V8 engine, complete with its own memory heap. Because Edge functions run within these lightweight isolates rather than full Node.js processes, they boot up in under 5 milliseconds.
// A simple Edge function (Cloudflare Worker syntax)
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
// A/B testing logic executed instantly at the edge
if (request.headers.get('cookie')?.includes('test=A')) {
return new Response('Showing version A');
}
return fetch(request); // Passthrough to origin
}
} Common Use Cases for Edge Computing
Edge computing isn't appropriate for every task. It excels in operations that require low latency and high concurrency:
- A/B Testing & Personalization: Modify the HTTP request/response on the fly based on cookies or geolocation without a trip to the origin.
- Authentication & Authorization: Validate JWTs at the Edge. If a token is invalid, reject the request immediately before it ever hits your primary database.
- Edge Rendering: React Server Components and SSR frameworks (like Next.js) can stream HTML directly from the edge, significantly reducing TTFB (Time to First Byte).
- Geographic Routing: Detect where a user is calling from and instantly route them to the nearest database replica.
The Database Problem at the Edge
The biggest hurdle in Edge computing is data. If your code executes in 5ms in Tokyo, but it needs to query a PostgreSQL database in Virginia, you've gained nothing. You still have to wait for the cross-ocean data transfer.
Furthermore, traditional databases use stateful TCP connections. If thousands of global Edge instances open TCP connections simultaneously, the database will crash (connection exhaustion).
The industry is solving this in three ways:
- HTTP-based Databases: Services like Upstash (Redis) or Supabase allow you to query the database via REST/HTTP, which the Edge handles perfectly.
- Distributed Edge Databases: Databases like Cloudflare D1 (SQLite) or Turso replicate data to the edge nodes themselves.
- Connection Poolers: Proxies that sit in front of traditional Postgres databases to manage the thousands of incoming Edge connections.