๐ŸŒdeveloper

Edge Functions vs Serverless Functions: What's the Difference and When to Use Each

Edge and serverless are not the same thing. Here's what distinguishes them, where each performs well, and which to reach for in common web dev scenarios.

Free to read

Advertisement

Both edge functions and serverless functions let you run code without managing servers. But they run in different places, with different constraints, and for different use cases. Mixing them up leads to either slow responses you thought would be fast, or runtime errors you didn't expect.

Serverless functions (Lambda, Vercel functions, Netlify functions)

Serverless functions run in a single region โ€” usually wherever you deployed them. They start cold (boot time of 100โ€“500ms on first request, sometimes more) and support the full Node.js runtime: file system operations, large npm packages, native bindings, and anything that runs in Node. The cold start is the main cost.

Edge functions (Cloudflare Workers, Vercel Edge Runtime)

Edge functions run at locations distributed around the world, geographically close to users. Request latency is much lower because the code runs nearby. The tradeoff: a restricted runtime. No Node.js APIs. No file system. Small binary size limits. Only web-standard APIs (fetch, Response, Request, crypto). No most npm packages.

Latency comparison

A serverless function in us-east-1 serving a user in Tokyo adds ~150ms of network latency before the function even starts running, plus cold start time. An edge function running in Tokyo adds ~5ms of network latency. For real-time user interactions, that difference is perceptible.

When to use serverless

  • Any API that needs a full Node.js environment โ€” database drivers, image processing, file parsing
  • Compute-heavy operations โ€” video transcoding, PDF generation, complex calculations
  • Long-running processes (edge functions have strict CPU limits, often <50ms)
  • Any function that needs to access resources in a specific region (a database in us-east-1)

When to use edge

  • Authentication โ€” checking JWTs before requests reach origin
  • Redirects and rewrites โ€” immediate response, no origin request
  • Geolocation-based personalization โ€” different content based on user country
  • A/B testing and feature flags โ€” decide which variant to serve before the page loads
  • Response modification โ€” adding headers, transforming responses

Performance tip

The best edge function is one that handles the request entirely at the edge without calling back to a serverless function or database. Every callback to origin defeats the latency benefit.

Advertisement

๐Ÿ”ง Free Tools Used in This Guide

PS

Priya Shah

Senior Software Engineer ยท 9+ years experience

Priya has nine years of experience building distributed systems and developer tooling at two B2B SaaS companies. She writes about APIs, JSON/JWT workflows, regex, DevOps, and the small utilities that make debugging faster at 2am.

View all posts by Priya Shah โ†’

Tags:

edge computingserverlessweb infrastructurevercelcloudflare