{"head":{"title":"What Is an Edge Function? Definition and Example | OceanLab","description":"An edge function is a small piece of code that runs on CDN servers close to the user. What it is good for, what it is not, an example and common mistakes.","canonical":"https://oceanlab.in/glossary/edge-function"},"crumbs":[{"name":"Home","path":"/"},{"name":"Glossary","path":"/glossary"},{"name":"edge function","path":"/glossary/edge-function"}],"slug":"edge-function","term":"Edge function","aka":["edge compute","edge worker"],"category":"Hosting and delivery","short":"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.","body":[["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 ",{"href":"/glossary/serverless","text":"serverless"}," compute that sits inside the ",{"href":"/glossary/cdn","text":"CDN"},". Good uses include redirects, auth checks, A/B routing, personalising cached pages and simple APIs."]],"why":["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."],"example":["A global store uses an edge function to read the visitor's country and send them to the right regional site with prices in their currency, before any page loads. The checkout API still runs in the main region next to the database."],"inBuild":["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 ",{"href":"/glossary/observability","text":"observability"}," tools."],"mistakes":[["Calling a single-region database from every edge location, which makes it slower than before."],["Expecting full server libraries to work in a limited runtime."],["Hiding business logic in edge code nobody remembers is there."]],"related":[{"href":"/glossary/cdn","label":"CDN (content delivery network)","detail":"A network of servers around the world that keeps copies of your files close to users, so pages and media load faster."},{"href":"/glossary/serverless","label":"Serverless","detail":"A 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."},{"href":"/glossary/cold-start","label":"Cold start","detail":"The extra delay when a serverless function or a new server instance has to start up before it can handle a request."},{"href":"/glossary/egress","label":"Egress (data transfer out)","detail":"Data that leaves a cloud provider's network, such as files sent to users, which many providers bill per gigabyte."},{"href":"/glossary/rate-limiting","label":"Rate limiting","detail":"Capping how many requests a user, API key or address can make in a given time, to protect a system and share capacity fairly."}],"tools":[],"links":[{"href":"/pricing/categories/edge-functions","label":"Edge function pricing","detail":"Edge compute prices, with sources."},{"href":"/pricing/categories/cdn","label":"CDN pricing","detail":"CDN and bandwidth prices, with sources."}],"sources":[],"legal":false,"updatedAt":"2026-10-25"}