Edge function
Server-side code that runs on a CDN's edge network, geographically close to the user, rather than on a single origin server.
Also known as: edge worker, edge compute
An edge function is server-side code that runs on the edge of a content delivery network (CDN), geographically close to the user, rather than on a single origin server in one location. Edge functions handle requests with very low latency because they execute in a data center near the user.
The term covers a few specific implementations: Cloudflare Workers, Vercel Edge Functions, Netlify Edge Functions, AWS Lambda@Edge, Fastly Compute, and others.
Why edge functions exist
Traditional serverless functions (AWS Lambda, Google Cloud Functions, Azure Functions) run in a small number of regional data centers. A user in Tokyo accessing a function hosted in Virginia incurs significant latency on each round trip.
Edge functions distribute the code globally, running it in dozens or hundreds of locations close to where users are. This makes them suitable for use cases that require low-latency server-side logic on every request.
How edge functions work
When a request arrives at the CDN edge:
- The CDN routes it to the nearest data center
- The edge function runtime executes the function in that location
- The function processes the request, possibly modifying headers, redirecting, fetching from APIs, or generating dynamic responses
- The response is returned to the user, often within tens of milliseconds
Edge function runtimes are typically based on V8 (Cloudflare Workers, Vercel Edge), WebAssembly (Fastly), or lightweight Node.js variants.
Common use cases
- A/B testing and experimentation. Decide which variant to serve based on cookie or header
- Authentication. Validate JWTs or session tokens before serving content
- Geolocation-based routing. Serve different content based on user country
- Personalization. Inject user-specific data into otherwise static pages
- Redirects. Handle complex redirect logic without origin involvement
- Image transformation. Resize or reformat images on the fly
- Bot detection and security. Filter or challenge suspicious requests
- API aggregation. Combine multiple backend API calls into a single edge response
- Server-side rendering at the edge. Render personalized HTML close to the user
Common edge function platforms
| Platform | Runtime | Notable features |
|---|---|---|
| Cloudflare Workers | V8 isolates | Free tier, large global network, durable objects |
| Vercel Edge Functions | V8 isolates (based on Cloudflare Workers) | Tight integration with Next.js |
| Netlify Edge Functions | Deno | TypeScript support, integrates with Netlify hosting |
| AWS Lambda@Edge | Node.js / Python | Tightly integrated with CloudFront |
| Fastly Compute | WebAssembly | Multiple language support |
| Deno Deploy | Deno (JavaScript / TypeScript) | Standards-based |
Edge functions vs traditional serverless
| Aspect | Edge function | Traditional serverless (Lambda, etc.) |
|---|---|---|
| Geographic distribution | Global, many locations | Few regional data centers |
| Cold start | Typically near zero (V8 isolates) | Higher, especially for some runtimes |
| Runtime restrictions | Limited APIs, no full Node.js | Full Node.js, Python, etc. |
| Execution time limits | Short (milliseconds to seconds) | Longer (up to 15 minutes for Lambda) |
| Best for | Per-request logic, personalization | Background jobs, longer computations |
Edge functions are not a replacement for traditional serverless; they target different use cases.
Limitations
- Limited execution time. Most edge platforms cap function duration at a few seconds
- Limited memory and CPU. Edge functions are designed for fast, lightweight work
- Restricted runtime. No file system, limited Node.js APIs, smaller dependency ecosystem
- No persistent local state. State must be stored externally (KV stores, durable objects, databases)
- Vendor-specific APIs. Code is often not portable between edge platforms without modification
Edge functions and static sites
Edge functions are commonly paired with static sites to add dynamic behavior without abandoning the static architecture:
- A static marketing site uses edge functions for form submission and analytics
- A static documentation site uses edge functions for search
- A static ecommerce site uses edge functions for cart, checkout, and personalization
This pattern keeps the bulk of the site fast and cacheable while enabling per-request customization where needed.
Common misconceptions
- “Edge functions replace backend servers.” They handle per-request logic at the edge, but persistent state (databases, file storage) still lives elsewhere.
- “All serverless is edge.” Edge functions are a subset of serverless; most serverless platforms are regional rather than global.
- “Edge functions are always faster.” They reduce latency for per-request logic, but if the function still needs to call a remote database or API, the savings can be partially offset.