Edge Functions
Code that runs at the edge of the network, close to users, for faster response times.
Edge functions run on servers distributed around the world, physically close to your users. Instead of all requests going to a single data center, they're handled by the nearest edge location.
Why edge matters: - Latency: 20ms from edge vs 200ms from origin - User experience: Faster responses feel snappier - Global reach: Consistent performance worldwide - Resilience: Failures are localized
What runs on the edge: - Authentication checks - A/B testing logic - Personalization - Geolocation-based routing - API rate limiting - Static content transformation
Edge vs Serverless: Traditional serverless runs in one or few regions. Edge functions run in dozens of locations worldwide. The trade-off is edge functions have more constraints (smaller runtime, fewer APIs).
Platforms: - Cloudflare Workers: Largest edge network - Vercel Edge Functions: Integrated with Next.js - Deno Deploy: Full Deno runtime at edge - Fastly Compute@Edge: Enterprise-focused
Considerations: - Limited runtime (no Node.js, often V8 isolates) - Smaller memory limits - Restricted API access - Cold starts are faster but still exist
Examples
- •Vercel middleware checking auth before page load
- •Cloudflare Worker doing A/B test assignment
- •Edge function personalizing content by country