3 min read
Edge vs Serverless functions

Two sibling services, supposed to carry the load of modern web

Okay let’s start with SERVERLESS Functions. They are a alternate way to do some processing on servers. When we want to spin up a process on a request or in a periodically manner, then renting a server for the entire time, would not be very cost or resource efficient. Also requires more brain-time to choose right kind of server for right duration.

That’s why cloud providers come with an option to host a process as a Function. And when that function/process needs to be executed, the cloud guys will quickly spin up a just-capable-enough server, execute that process and shut that server down once the whole thing is done. This way we only pay for the time that server has run or (indirectly) for the time our code/process has run. And we don’t need to worry about the server configurations anymore. But at this level, we still need to put these functions at different cloud locations.

Instead, if we put these functions at CDNs across the globe, we call them EDGE Functions. Edge is smaller sized server that is underpowered and lives very close to user. It is not powered enough to handle NodeJs as its runtime. So it has its own runtime : Edge Runtime (every edge provider call their runtime something different). It is still capable enough to deliver Web/Javascript Assets and do some minor Javascript processing (things like NextJS Middlewares). When a user requests for a site, it goes to the nearest server (edge) and not to far living, bigger, actual server.

This way it seems fast, but when things like API routes are hosted on the Edge, things might take more time, because the DB that API route is calling sits at the actual server. So the Edge has to reach to the far-living sever to get the data and server it back.