Lesson 3 of 9 · 18m
Deciding What Belongs at the Edge
A practical decision framework: latency, state, consistency, and blast radius matter more than fashion.
The wrong question is "can this run in a Worker?" Almost anything can be bent into one. The right question is whether moving logic to the edge reduces user-perceived latency or operational risk without creating a consistency problem you now have to own forever.
The four-part test
Ask these in order:
- Latency: does this decision need to happen before the request travels to the origin?
- State: can it run with local, cached, or eventually consistent data?
- Failure: if the edge logic fails, do we degrade gracefully or take the whole product down?
- Ownership: who can debug it at 2 a.m. — the app team or whoever happens to know Cloudflare?
If the answer to #1 is no, putting it at the edge is usually resume-driven architecture. If #2 is no, you are building a distributed database by accident.
Good edge citizens
- JWT or session-token verification using public keys or cached metadata.
- A/B assignment, geolocation routing, device-aware rendering, redirects.
- Header normalization, request validation, API versioning, protocol adaptation.
- Serving stale or degraded content during origin outages.
- Bot filtering and cheap admission control before expensive origin work.
A classic example is authentication gating:
const payload = await verifyJwt(token, env.AUTH_PUBLIC_KEY);
if (!payload) return Response.redirect(`${url.origin}/login`, 302);
request.headers.set("x-user-id", payload.sub);
return fetch(request);The edge can reject unauthenticated traffic without waking the origin. It should not decide nuanced authorization that depends on current account state unless that state is deliberately replicated.
Bad edge citizens
- Checkout totals, inventory reservation, money movement, or anything requiring strong global consistency.
- Long-running reporting or transformation pipelines.
- Business workflows hidden in glue code nobody sees in the application repository.
- "Just a little cache" around data whose correctness depends on per-user permissions.
Field notes
- Edge logic must live in version control and deploy like application code. Console-edited Workers are an incident waiting for a timestamp.
- Put a kill switch in front of every routing experiment: an env var or config binding beats an emergency deploy.
- Complexity at the edge compounds with complexity at the origin. If both need the same rules, extract the rules instead of duplicating them badly.
- The best edge architectures are thin at the edge and honest about it.
Was this lesson helpful?