A team wants to run personalized A/B test bucketing logic on every request at the CDN edge (for example, using Cloudflare Workers or a similar edge-compute platform) instead of in their origin application server. What kinds of logic are a good fit for that edge-compute layer, and what would make you push back and say 'this belongs in the origin, not the edge'?
answer
- edge compute = short sandboxed functions run at PoPs
- good fit: cheap, stateless, per-request logic
- bad fit: heavy compute, strong consistency, long execution
- cold starts + limited runtime + per-invocation pricing
- global deploy usually means no built-in regional canary
basics
~20 sEdge compute runs small pieces of code on the CDN's servers near the user, so simple, fast decisions like which test group to show, or rewriting a URL, can happen instantly without a trip to the main server. It's a bad fit for anything needing a big database, heavy computation, or long-running work, because edge servers are deliberately limited and don't reliably keep state.
solid answer
~50 sEdge compute platforms run short-lived, sandboxed functions directly on CDN PoPs, triggered per-request before or instead of hitting origin. Good fits are cheap, stateless, latency-sensitive operations: A/B bucket assignment from a cookie or deterministic hash, header/URL rewriting, auth token validation, geo-based redirects, or serving cached responses with light personalization — things that run on nearly every request and benefit from executing near the user instead of round-tripping to origin. Push back when logic needs significant CPU or memory, long execution time, large or strongly-consistent state, or access to internal-network-only resources — edge runtimes intentionally cap execution time and memory, have no reliable persistent local state, cold-start on first invocation at a given PoP, and are priced per-request or per-CPU-millisecond, which gets expensive fast for heavy logic. If the A/B logic starts needing joined data from several backend services, that's a sign it belongs in origin, or the edge function should just read a precomputed bucket rather than compute one.
go deeper
Doesn't need this; a general notion that 'some CDNs can run small bits of code' is plenty at this level.
Should know edge compute exists as a category and be able to name one or two example platforms.
Should list good and bad fits for edge logic and name the core constraints — execution time, statelessness, cold starts.
Should make the build-vs-place decision for a platform's overall architecture: which class of logic belongs at the edge versus origin, accounting for consistency requirements, deployment/rollback safety, vendor lock-in, and the shift in cost model at scale.
## What edge compute is Edge compute platforms — **Cloudflare Workers**, **Fastly Compute**, and **Lambda@Edge/CloudFront Functions** are the well-known examples — let a developer deploy a small function that runs on the CDN's own PoPs, intercepting a request before it would otherwise be handled purely as a cache lookup or forwarded to origin. Mechanically, these are typically short-lived, sandboxed execution environments: Cloudflare Workers, for instance, run inside **V8 isolates** (the same lightweight JavaScript execution sandbox that powers a browser tab, minus the browser around it), which start far faster than a full container or VM but are correspondingly constrained in what they can do. A request hits a PoP, the edge function runs synchronously as part of handling it — reading headers, cookies, or the URL, and deciding to rewrite the request, answer immediately from logic alone, or forward it onward to a cache lookup or the origin — and the response continues on its way. ## Why this layer exists The reason this layer exists is to push cheap, per-request decisions as physically close to the user as possible, shaving away round trips that would otherwise require a full trip to origin just to make a small decision. Two things converge to make this valuable: 1. **The latency argument** from CDN PoP placement generally — deciding something in Tokyo instead of Virginia saves the same round trip that caching a static file does. 2. **An economic argument** — offloading simple, high-volume logic (like assigning an A/B test bucket on every single page view) from the origin fleet to the CDN's compute layer can meaningfully reduce origin server count and cost at scale, since the edge absorbs work that would otherwise all funnel back to one place. ## The trade-off The trade-off is that edge runtimes are deliberately, not incidentally, constrained. - **Execution time and memory are capped**, often quite tightly, to keep the sandbox lightweight and fast to start; there's usually no arbitrary native dependency support, ruling out heavyweight libraries or long-running computation. - **State is the sharper constraint.** An edge function instance is ephemeral and tied to one PoP, with no reliable local persistent storage — anything that needs to be read or written durably has to go through a separate edge key-value store (itself typically eventually consistent across PoPs, replicating asynchronously) or back to origin, both of which reintroduce some of the latency the edge was supposed to avoid. - **The billing model shifts too**, from provisioning server-hours to paying per invocation or per unit of CPU time, which is cheap for lightweight logic run at massive scale but can become expensive quickly if the logic is heavier than it should be. ## Failure modes Failure modes cluster around exactly these constraints being violated or underestimated. - **Cold starts** — the cost of initializing a fresh isolate the first time (or after eviction) a function runs at a given PoP — can spike tail latency noticeably for lower-traffic routes or less-visited PoPs, unlike an always-warm origin server pool. - **Treating an edge KV store as if it offered strong, immediate cross-region consistency** is a classic mistake: a value written in one region may not yet be visible to a function running in another PoP, which is fine for something like A/B bucketing (a few seconds of eventual staleness is harmless) but genuinely dangerous for something like a real-time inventory decrement or an account-suspension check, where a stale read can cause overselling or a security gap. - **Deployment risk is structurally different** from origin deployments: edge function updates typically roll out to every PoP globally at once, with no built-in per-region canary the way a fleet of origin servers can be updated region by region, so a bug in an edge function can affect essentially all global traffic almost immediately unless the team has built its own staged rollout tooling on top of the platform. - **A practical vendor lock-in cost:** edge runtimes expose proprietary APIs (their own KV store, their own request/response object shapes) that don't port cleanly between providers. ## The heuristic In practice, the right heuristic is: - **Keep at the edge** whatever is cheap, mostly stateless, and tolerant of eventual consistency — A/B bucketing from a deterministic hash of a stable cookie value, security header injection, simple auth-token format validation, geo-redirects, or lightweight response personalization. - **Keep at origin** anything that needs strong consistency, meaningful compute, or coordination across multiple backend systems, such as checkout and payment logic, or any decision that must never be stale even for a few seconds.
- What causes cold starts in edge compute platforms, and why do they matter more here than in a traditional origin server pool?A runtime instance has to be initialized at a given PoP the first time (or after being evicted) a function is invoked there, adding latency to that particular request; it matters more at the edge because a lower-traffic route can go long enough between requests at a given PoP that cold starts happen fairly often, unlike a warm, continuously-running origin fleet.
- If an edge function needs to check a value that must be strongly consistent across all PoPs — for example, whether an account was just suspended — what's the risk of implementing that check purely at the edge?Most edge key-value stores replicate asynchronously and are only eventually consistent across PoPs, so a suspension flag set in one region might not yet be visible at another PoP, meaning the edge check could momentarily approve an action that should have been blocked; for anything requiring strong consistency, the safer design keeps that check at origin or explicitly accepts the eventual-consistency window.
- Why is deploying a buggy edge function riskier in some ways than deploying a buggy change to an origin server fleet?Edge deployments typically push to every PoP globally at essentially the same time, so there's no natural per-region canary the way an origin fleet can be rolled out region by region; a bug can therefore affect close to 100% of global traffic almost immediately unless the team has built its own staged or percentage-based rollout tooling on top of the platform.
Edge compute is like giving every neighborhood pizza branch a laminated decision card ('if the customer says X, do Y') instead of calling headquarters for every order — great for split-second, simple decisions, but the moment a decision needs headquarters' full customer database or a long negotiation, the branch has to call HQ anyway, so the laminated card doesn't help.
saying these in an interview costs you the question
- Wants to move any and all logic to the edge simply because it sounds faster, without weighing the constraints
- Doesn't know edge functions are typically stateless and ephemeral per PoP
- Assumes edge compute has the same resource ceilings as a normal origin server
- Unaware that edge key-value/state stores are typically eventually consistent across PoPs
- Treats edge deploys as safely canary-able by default without extra tooling