← Lessons

quiz vs the machine

Gold1440

System Design

The Edge Compute Functions

Running small code at the edge to shape requests and responses.

5 min read · core · beat Gold to climb

Beyond static caching

A CDN can do more than serve files. Edge compute functions run lightweight code at the PoP, right next to the user. They execute in milliseconds inside a sandboxed runtime, often started cold in well under a second.

Common uses

  • Request rewriting such as adding headers, routing, or redirects.
  • A and B testing by choosing a variant near the user.
  • Auth checks like validating a token before a cache lookup.
  • Personalization of small response fragments without an origin call.

Two flavors

  • Viewer functions run on each user request and response, so they must be tiny and fast.
  • Origin functions run only on cache miss, so they can do heavier work like response assembly.

Limits to respect

Edge runtimes cap CPU time, memory, and bundle size. They are not a place for long jobs or large dependencies. The goal is to push light, latency sensitive logic close to users while leaving heavy work to regional services.

Key idea

Edge functions run light logic at the PoP to rewrite, route, and personalize close to users, within tight CPU and memory limits.

Check yourself

Answer to earn rating on the learn ladder.

1. When does an origin edge function typically run?

2. What is a key constraint of edge compute?