Skip to content
Edge Functions: Running Code at the CDN Layer 2 min

Edge Functions: Running Code at the CDN Layer

SD
ScaleDojo
May 11, 2026
2 min read370 words
Edge Functions: Running Code at the CDN Layer

Vercel's 1ms Response Times

Vercel serves Next.js applications from edge functions running in 30+ regions. A user in Mumbai gets their personalized page from a function running in Mumbai - not from a US-East server. The response time is often under 10ms, which feels instant. The function runs AT the CDN node, eliminating the round trip to a central origin entirely.

What Edge Functions Can Do

Edge Function Use Cases:

Use Case              Without Edge         With Edge
--------------------  ------------------   ------------------
A/B testing           Origin decides       Edge rewrites URL
                      (200ms+ round trip)  (5ms, no origin)

Auth verification     Origin validates     Edge verifies JWT
                      JWT (200ms+)         (5ms, blocks bad)

Geo-routing           Client-side detect   Edge reads IP geo
                      (slow, inaccurate)   (instant, accurate)

Image resize          Pre-generate all     Resize on-the-fly
                      sizes (storage cost) (compute at edge)

Bot detection         Origin processes     Edge challenges
                      bot traffic (waste)  bots before origin

Localization          Origin renders       Edge substitutes
                      per-locale page      content by header

V8 Isolates vs Containers

Cold Start Comparison:

Approach        Cold Start   Memory    Isolation
--------------  ----------   --------  ----------------
Full container  100-500ms    128MB+    Process-level
(Lambda@Edge)                          (strong)

V8 Isolate      < 1ms        ~2MB      V8 sandbox
(CF Workers)                           (Chrome tabs)

Why V8 Isolates are faster:
  Container: boot OS -> load runtime -> load code -> run
  V8 Isolate: load V8 -> run (same engine as Chrome)

  At 100,000 req/s, cold starts matter enormously.
  1ms cold start: imperceptible
  500ms cold start: visible to users on first request

  Trade-off: V8 Isolates have
  - No file system access
  - Limited CPU time (10-50ms)
  - No native code/C extensions
  - JavaScript/TypeScript/WASM only

Edge Platforms Compared

Platform           PoPs    Runtime       Cold Start  Limits
-----------------  ------  -----------   ----------  -----------
Cloudflare Workers 310+    V8 isolate    < 1ms       10ms CPU
Vercel Edge Func   30+     V8 isolate    < 5ms       30s timeout
AWS Lambda@Edge    200+    Container     ~100ms      30s/5MB
Deno Deploy        35+     V8 isolate    < 1ms       50ms CPU
Fastly Compute     80+     WASM          < 1ms       Custom

Choose Cloudflare: most PoPs, cheapest, fastest cold start
Choose Lambda@Edge: already on AWS, need full Lambda features
Choose Vercel: Next.js app, integrated deployment

Interview Tip

When discussing latency optimization, say: 'For logic that does not need database access - like authentication, A/B testing, geo-routing, or bot detection - I would move it to edge functions running at CDN PoPs worldwide. This eliminates the origin round trip, giving sub-10ms response times globally. I would use Cloudflare Workers for their V8 isolate architecture which has sub-millisecond cold starts, compared to Lambda@Edge containers which can add 100ms+ on cold starts.'

<
Edge Functions: Running Code at the CDN Layer - Architecture Diagram
Architecture overview
/blockquote>

Key Takeaway

Edge functions execute code at CDN nodes globally, enabling sub-10ms response times for logic that previously required an origin round-trip. Use them for A/B testing, auth, routing, and personalization. Cloudflare Workers (V8 isolates) offer better cold start performance than Lambda@Edge.

Enjoyed this article?

Share it with your network to help others level up their system design skills.

Discussion0

Join the Discussion

Sign in to leave comments, reply to others, or like insights.

Sign In to ScaleDojo

No comments yet. Be the first to start the thread!

Related Articles

Enjoyed this content?

Your support keeps us creating free resources

We put a lot of hours into researching and writing these guides. If it helped you, consider buying us a coffee. Every bit goes toward keeping ScaleDojo's content free and growing.

$

One-time payment via Stripe. ScaleDojo account required.

ScaleDojo Logo
Initializing ScaleDojo