diagram.mmd — sequence
Edge Function Execution sequence diagram

Edge function execution describes how a lightweight JavaScript or WASM function runs at a CDN Point of Presence (PoP) — geographically close to the user — to handle request routing, response manipulation, personalization, or authentication without a round trip to the origin server.

What the diagram shows

This sequence diagram follows a request through Client, CDN Edge Node, Edge Function Runtime, and Origin Server.

The flow demonstrates three capabilities edge functions provide:

1. Request interception: the edge node intercepts the inbound request before it reaches origin. The edge function runs and inspects request headers, cookies, and URL. 2. Cache bypass or rewrite: the function can rewrite the URL, modify request headers, or short-circuit with a response from the edge (e.g., serving a cached variant or redirecting based on geolocation). 3. Origin fetch and response manipulation: if the function decides to forward to origin, it can modify the origin response before it reaches the client — injecting headers, transforming HTML, or A/B testing by swapping content.

The diagram also shows the case where the edge function generates a full response directly (e.g., returning a JSON API response or redirect) without contacting origin at all.

Why this matters

Edge functions reduce latency dramatically for personalization and auth logic that previously required a round trip to a centralized origin. Platforms like Cloudflare Workers, Vercel Edge Functions, and Fastly Compute@Edge use V8 isolates instead of containers, achieving sub-millisecond cold starts — a key difference from the Serverless Request Flow model with its container-based cold starts.

For static asset delivery without function logic, see the networking CDN Request Flow. The API Gateway Request Flow covers a similar interception pattern but at the origin infrastructure layer rather than the CDN edge.

Free online editor
Edit this diagram in Graphlet
Fork, modify, and export to SVG or PNG. No sign-up required.
Open in Graphlet →

Frequently asked questions

Edge function execution describes how a lightweight JavaScript or WebAssembly function runs at a CDN Point of Presence (PoP) — geographically close to the user — to handle request routing, response manipulation, personalization, or authentication without a full round trip to the origin server. This reduces latency by processing logic at the network edge rather than at a centralized data center.
When a request arrives at a CDN edge node, the node intercepts it before forwarding to origin. The edge function runtime (using V8 isolates, not containers) initializes and executes the function code. The function can inspect request headers and cookies, rewrite the URL, return a cached response directly from the edge, or forward to origin and modify the origin's response before it reaches the client.
Use edge functions for logic that benefits from geographic proximity to the user: A/B test assignment, geo-based redirects, personalized content injection, JWT validation, and bot detection. Any logic that currently requires a round trip to a centralized server — but doesn't need a database — is a candidate for moving to the edge.
Edge functions run at CDN PoPs distributed globally, using V8 isolates that start in sub-millisecond time with no container cold start. Serverless functions run at a fixed cloud region, use container-based execution environments, and have cold starts that can add hundreds of milliseconds. Edge functions are constrained in runtime (no Node.js APIs, limited execution time) while serverless functions have a much richer execution environment. Choose edge for ultra-low-latency stateless logic; choose serverless for complex, stateful, or long-running operations.
mermaid
sequenceDiagram participant C as Client participant EN as CDN Edge Node participant EF as Edge Function Runtime participant OS as Origin Server C->>EN: HTTP request (nearest PoP) EN->>EF: Trigger edge function EF->>EF: Inspect request headers and URL EF->>EF: Check geolocation and user attributes alt Short-circuit response at edge EF-->>EN: Return edge-generated response EN-->>C: HTTP response (no origin hit) else Forward to origin with modifications EF->>EF: Rewrite URL or inject request headers EF->>OS: Forward modified request OS->>OS: Process request OS-->>EF: Origin response EF->>EF: Manipulate response headers or body EF-->>EN: Modified response EN-->>C: HTTP response end
Copied to clipboard