Skip to main content

Edge Function Latency: CDN PoP Comparison & Optimization Guide

Edge functions run your code at CDN points of presence globally, delivering sub-50ms latency to users worldwide. This guide compares providers, benchmarks real-world latency, and defines exactly when edge functions outperform regional serverless.

โœ“ Cloudflare vs Vercel vs Fastly comparison โœ“ P95 latency benchmarks โœ“ Near-zero cold starts explained โœ“ Edge vs regional decision guide

Edge Function Platform Comparison

Provider PoPs P50 Latency Cold Start CPU Limit Runtime
Cloudflare Workers300+5-30ms<5ms10ms / 50msV8 Isolates
Vercel Edge Functions~3005-35ms<5ms~50msV8 Isolates (CF)
Fastly Compute100+10-50ms<1ms50ms defaultWASM
AWS Lambda@Edge~20 regional50-150ms100-500ms5 secondsNode.js / Python
Deno Deploy35+10-60ms<5msNo hard limitV8 (Deno)

Use Case 1: Authentication at the Edge

Validate JWTs or session cookies before requests reach your origin, eliminating unauthorized traffic entirely:

// Cloudflare Worker โ€” JWT validation at edge
export default {
  async fetch(request: Request): Promise<Response> {
    const authHeader = request.headers.get('Authorization');

    if (!authHeader?.startsWith('Bearer ')) {
      return new Response('Unauthorized', { status: 401 });
    }

    const token = authHeader.slice(7);

    try {
      // Verify JWT using Web Crypto API (available at edge)
      const isValid = await verifyJWT(token, JWT_SECRET);
      if (!isValid) return new Response('Invalid token', { status: 401 });
    } catch {
      return new Response('Auth error', { status: 401 });
    }

    // Token valid โ€” forward to origin
    return fetch(request);
  }
};
// Result: Auth check adds ~5ms, unauthorized requests never hit origin

Use Case 2: Geo-Redirect at Edge

// Vercel Edge Middleware โ€” geo-based redirect
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';

export function middleware(request: NextRequest) {
  const country = request.geo?.country ?? 'US';
  const url = request.nextUrl.clone();

  // Redirect EU users to GDPR-compliant domain
  if (['DE', 'FR', 'IT', 'ES', 'NL'].includes(country)) {
    url.hostname = 'eu.example.com';
    return NextResponse.redirect(url, 302);
  }

  // Add geo header for origin to use
  const response = NextResponse.next();
  response.headers.set('x-user-country', country);
  return response;
}

export const config = {
  matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
// Geo data available from CF headers โ€” no external API call needed

Edge vs Regional Serverless: Decision Guide

Requirement Edge Functions Regional Lambda
Database queriesHTTP-only (PlanetScale/Neon)Full support
Global low latencyExcellent (<50ms)Region-dependent
Long computationsNot suitable (>50ms)Up to 15 min
JWT/cookie authIdeal use caseWorks but slower
VPC resourcesNot supportedFull support
A/B testing headersIdeal use casePossible but adds origin RTT
Share this tool: X / Twitter LinkedIn
โœ“ 60,000+ developers use DevPlaybook โ˜…โ˜…โ˜…โ˜…โ˜… 4.8 / 5 on Gumroad โœ“ MIT licensed ยท Instant download โœ“ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • โšก AI Code Review, Doc Generator & SQL Builder
  • โšก All premium templates & early access
  • โšก Member discounts on Gumroad products
Start Free Trial โ†’

$9/mo after trial ยท Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products โ€” grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro โ€” $79 โ†’

MIT licensed ยท Instant download ยท No subscription

See what's included โ†’ Browse all deals โ†’

Frequently Asked Questions

What are edge functions?▼

Edge functions are serverless functions that run at CDN points of presence (PoPs) distributed globally, rather than in a single cloud region. They execute within milliseconds of the end user's location. Major providers include Cloudflare Workers (300+ PoPs), Vercel Edge Functions (based on Cloudflare), and Fastly Compute (100+ PoPs). Edge functions use the V8 isolates model rather than full Node.js, giving them near-zero cold starts.

What is the latency difference between edge functions and regional Lambda?▼

Edge functions typically add 5-50ms of latency to a user request because execution happens at the nearest CDN PoP. Regional Lambda (e.g., us-east-1) adds 80-250ms for users in that region, but 200-500ms+ for users on other continents. For global audiences requiring low latency, edge functions provide consistently fast response times regardless of user location.

Do edge functions have cold starts?▼

Edge functions using the V8 isolates model (Cloudflare Workers, Vercel Edge) have near-zero cold starts โ€” typically under 5ms โ€” because isolates are much lighter than full process/container environments. Fastly Compute using WebAssembly also achieves sub-millisecond cold starts. This is a significant advantage over regional Lambda which can have 100ms-4000ms cold starts depending on runtime.

What are the limitations of edge functions compared to regional serverless?▼

Edge functions have significant constraints: CPU time limits (1-50ms per request), memory limits (128MB), no persistent connections (no TCP database connections), limited Node.js APIs, and no file system access. They cannot run long computations, maintain WebSocket connections over time, or access VPC resources. For database-heavy logic, prefer regional Lambda or use edge-compatible databases like PlanetScale's HTTP driver.

When should I use edge functions vs regional Lambda?▼

Use edge functions for: JWT/cookie validation before hitting origin, geolocation-based redirects, A/B testing header injection, bot detection, rate limiting at CDN layer, and serving personalized cached responses. Use regional Lambda for: database queries, complex business logic, third-party API calls requiring persistent connections, operations exceeding 50ms CPU time, and anything requiring VPC access.

Which CDN provider has the most edge locations?▼

Cloudflare leads with 300+ PoPs across 100+ countries. Fastly has 100+ PoPs. Vercel Edge Functions run on Cloudflare's infrastructure. AWS CloudFront has 450+ distribution points but Lambda@Edge runs only in ~20 regional edge locations (not all PoPs). For maximum geographic coverage, Cloudflare Workers provides the widest distribution.