Blog Edge functions vs serverless: which one, when
Edge functions vs serverless: which one, when
TL;DR Serverless functions run in a few data centres with full runtimes and easy access to databases. Edge functions run in many locations close to users with a lighter runtime and tight limits. Use edge for fast, small tasks near the user; use serverless for heavier work and data-backed logic.
Both edge and serverless functions let you run backend code without managing a server. They sound interchangeable, and cloud marketing does not help. But they make different tradeoffs, and picking the wrong one shows up as either latency or a limit you keep hitting.
Serverless functions
The original model. Your code runs in one of a handful of regions, spun up on demand. You get a full runtime, generous limits on time and memory, and easy access to databases and the wider ecosystem.
The catch is distance. If your function runs in one region and a visitor is on the other side of the world, every call pays for that round trip.
Edge functions
Edge functions run in many locations close to users, at the network's edge. That proximity makes them fast for the user. The cost is a lighter runtime: tighter limits on execution time and memory, and a smaller set of available APIs. They are built for quick work, not heavy lifting.
How to choose
The question is what the code needs to be near.
- Near the user? Use edge. Request rewriting, auth and redirect checks, header tweaks, light personalisation. Small, fast, latency-sensitive tasks.
- Near your data, or doing real work? Use serverless. Database-backed logic, heavier compute, anything that needs a full runtime or more time.
A useful instinct: if the function's main job is talking to a database, running it at the edge often just moves the latency from the user to the database call. Put it near whatever it talks to most.
The pragmatic take
Most apps use both. Edge handles the fast front-line work close to visitors; serverless handles the heavier, data-backed logic behind it. You do not have to pick one for everything. Match each function to what it needs to be close to, and the choice usually makes itself.
FAQ
What is the core difference between edge and serverless?
Location and runtime. Serverless functions run in a handful of regions with a full runtime and generous limits. Edge functions run in many points of presence near the user, on a lighter runtime with stricter limits on time, memory, and available APIs.
When should I use an edge function?
For small, fast tasks that benefit from being close to the user: rewriting requests, auth checks, redirects, personalisation, and setting headers. Anything where the round trip to a distant region would add noticeable latency.
When is plain serverless the better choice?
For heavier compute, long-running work, or logic that talks to a database. Serverless gives you a fuller runtime and fewer limits, and putting it near your data often matters more than being near the user.