DEV Community


Posted on

What is Edge compute? Everything you need to know🧐

These are the primary edge compute providers.

  1. Cloudflare Workers
  2. Deno Deploy

There is also AWS lambada@edge which is just lambda function at edge locations, however the runtime is still node and suffers from cold start so it's not worth talking about. All others edge providers just resell edge functions from these providers. For example, Vercel edge is just Cloudflare workers under the hood. Netlify and Supabase edge is just Deno Deploy.

First of all, what exactly is edge compute?

"Edge" can refer to either edge locations(servers close to users) or edge runtime or both. Above I mentioned, AWS's lambda@edge is just node runtime at edge locations. Edge compute offers better performance, faster loads, and cheaper cost when compared to regular serverless functions like lambda/google functions. It's not controversial to say Edge will be the future of cloud compute.

There are 2 category of edge providers.

  • Edge functions: Cloudflare Workers & Deno Deploy
    • Cloudflare Workers and Deno Deploy run on V8 isolate(like your browser) and have their own unique runtime with a limited set of web APIs. These edge functions have zero cold start time. Each instant is like opening a new browser tab and can only handle one request. Functions auto-scale up and down and scale to zero by default. To deploy to edge runtime you must only use supported web APIs. Some tools don't support edge runtime so keep that in mind, prisma for example can't run on edge.
  • Edge containers:
    • run actual containers. This gives you much more control. You can pick your runtime, read/write to the file system, and even have an embedded SQLite database for insane performance. Containers are much more resource efficient and can handle many request concurrently. Fly's container auto-scale up and down like serverless functions. Fly's container does not scale to zero by default but can be opt-in to do so. They claim to have cold start time of only 100-200ms which is similar to lambda functions.

In general, functions will be cheaper early on while container will become more and more cost efficient as you scale up. Containers can perform many more actions than functions but also require more manual configuration.

Actually, I lied.

Edge does NOT always give you better performance. This depends upon where your database is located. To always get better performance, you need to use an "Edge database". It's exactly as it sounds, distributed database around the globe. Now your edge functions/containers will uses the nearest edge database. The most popular fully-managed edge database is Turso. There is also LiteFS from which is an embedded database. Meaning it runs in the same container as your app, this gives you INSANELY low latency, however it's not fully-managed so keep that in mind. Practically speaking, any edge database has to use SQLite. That is because it is extremely cheap to replicate compared to mySQL/PostgreSQL. It's not impossible but just not practical. If you are not using edge database, it is recommended to limit your edge to a single region closest to your database. Technically, it's no longer "edge" but you will still benefit from no cold start and lower cost.

Looking to learn Next.js 13 app router using the latest cutting-edge tech stack? Check out my project. It runs 100% on edge btw.



Like this article? Follow me on X (formerly Twitter) for tech advice and hot takes.

Top comments (0)