Edge function
Also called edge compute, edge worker.
A small piece of server code that runs on a CDN's servers around the world, close to the user, instead of in one central region.
Last updated
What it is.
Edge functions run in many locations at once and handle a request before, or instead of, your main server. They usually run on lightweight runtimes, start very quickly and have limits on run time, memory and which libraries can be used.
They are a kind of serverless compute that sits inside the CDN. Good uses include redirects, auth checks, A/B routing, personalising cached pages and simple APIs.
Why it matters
Running logic near the user cuts delay for every request it handles. But if the function has to call a database in one far-away region, the time saved is lost on that call. Edge is a fit for logic that needs little data or data that is copied close by.
In a product build
We put routing, auth checks and caching logic at the edge, and keep data-heavy work next to the database. Edge code is kept small and tested against the platform's runtime limits, and logs from every location feed into the same observability tools.
Common mistakes.
- 01
Calling a single-region database from every edge location, which makes it slower than before.
- 02
Expecting full server libraries to work in a limited runtime.
- 03
Hiding business logic in edge code nobody remembers is there.
Related terms.
- CDN (content delivery network)A network of servers around the world that keeps copies of your files close to users, so pages and media load faster.
- ServerlessA cloud model where the provider runs your code on demand and manages the servers, and you pay for what you use rather than for idle machines.
- Cold startThe extra delay when a serverless function or a new server instance has to start up before it can handle a request.
- Egress (data transfer out)Data that leaves a cloud provider's network, such as files sent to users, which many providers bill per gigabyte.
- Rate limitingCapping how many requests a user, API key or address can make in a given time, to protect a system and share capacity fairly.
Guides and pages
Browse the full glossary or read answers to common questions.