QuorumWiki
Jugar

Función edge

Ejecuta pequeños handlers junto al usuario: 5 ms, sin arranque en frío y un techo de CPU en lugar de una máquina.

Esta página aún no está traducida al español.

The Edge Function runs small handlers in the CDN, next to the user, as Cloudflare Workers and Fastly Compute do.

When to place it#

  • Place it when users are far from your origin and the handler is small: a redirect, a header rewrite, a cached read, a personalized page. It unlocks with Edge compute in Series C, after Content delivery, for 80,000 ◇.

  • Skip it for CPU-heavy kinds, such as an upload's image resize, an export or a login's password hash. They belong on an App Server.

  • Copy it when users in another region need it, since one Edge Function serves only its own region.

How it works#

It serves only its own region: a user there reaches it in 5 ms instead of the round trip to your origin, and a user in another region still pays that trip. It answers every request kind the way an App Server does, turning it into the backend calls it makes. Cold starts barely register: a V8 isolate starts in under 5 ms, against the seconds a container or a JVM takes.

A live Edge Function also holds the edge key-value cache that a CDN answers read from. That cache answers 30% of API reads, which the CDN alone answers at 0%.

It bills per request, on the Requests line of the cloud bill, and nothing while it idles.

Ceilings#

Edge Functions have no instance type and no size to pick. Two ceilings stand in for one:

  • CPU. A request may spend 10 ms of CPU. Past it the handler is killed and the request fails as a timeout.

  • Memory. A handler runs in 128 MB of isolate, which fits a small handler and its response but not a working set.

It runs your Service's Stack, so the Stack has to compile to the edge: JavaScript and TypeScript, or Rust and Go built to WebAssembly. A PHP, Ruby, Python, Java, C#, Elixir, Zig or Haskell Stack is refused there, and the card says so.

How it fails#

  • The CPU ceiling. A request that needs more than 10 ms of CPU is killed mid-flight, so an upload, a report or an export does not belong here.

  • The Stack. A Company that runs PHP cannot use the edge at all. The fix is a migration to a Stack that compiles, not a second edge Node.

  • The data tier. A handler that calls a Database on every request pays the round trip anyway, so it saves the user hop and not the query.

Certificate expired#

  • Signs: The Certificate expired banner appears, and every request through the Edge Function fails, as through every other TLS Node.

  • Do now: Click Renew in the banner.

  • Prevent: Research Certificate automation and place a Secrets and Certificates Node, which renews the certificates before they run out.

Region outage#

  • Signs: One region's board goes grey and the Edge Function in it goes down.

  • Do now: Press Fail over on the banner. It needs Multiple zones and a second open region, and starts the Node again in the nearest other region, cold, for the price of a replacement. Otherwise it comes back when the incident ends: 180 sim seconds in the catalog, 60 once the error budget counts.

  • Prevent: Research Multiple regions, keep a copy in a second region, and add GeoDNS to send users there.

Tips#

  • Pair it with a CDN, so the edge answers what the CDN cannot cache and the CDN answers the rest.

  • Keep the handler small. Treat the isolate's ceiling as a design constraint, not a bug to work around.

Reglas#

  • Cada copia adicional cuesta un 25% más que la anterior.
  • Al venderlo se devuelve el 50% de lo que costó su última copia.
  • Tiene un solo tamaño.

Funciona con#

Servidor de aplicaciones, CDN, Secretos y certificados