# System Design Interview: Global Content Delivery and Edge Computing

Source: https://www.techinterview.org/post/3233460954/system-design-edge-computing/
Updated: 2026-04-16 · techinterview.org

## Beyond Basic CDN: Edge Computing

A CDN (Content Delivery Network) has historically served static assets — images, CSS, JS — from geographically distributed servers (PoPs). Edge computing extends this by executing logic at the edge: authentication, A/B testing, request routing, personalization, and API responses — without a round-trip to the origin server. This reduces latency from 200ms+ (origin in another region) to 5-20ms (edge PoP in the user's city). Cloudflare Workers, Lambda@Edge, and Fastly Compute@Edge are the major platforms.

## CDN Architecture

### Two-Tier Cache Hierarchy

Modern CDNs use a two-tier hierarchy to maximize cache efficiency:

- **Tier 1 (edge PoPs)**: 200-300 geographically distributed PoPs, each with 1-10TB of SSD cache. A miss at the edge PoP does not immediately hit the origin.

- **Tier 2 (origin shield / mid-tier)**: 10-20 regional PoPs with much larger cache (100TB+ HDD). A Tier 1 miss fetches from the nearest Tier 2 PoP. Only a Tier 2 miss hits the origin.

For popular content (CDN hit rate 95%+), the origin receives very few requests. The Tier 2 layer is the "origin shield" — it absorbs the long-tail misses and serializes requests to the origin, preventing thundering herds when a popular object expires simultaneously from many Tier 1 PoPs.

### Cache Invalidation Strategies

After a deployment or content update, stale cached content must be invalidated or updated:

- **TTL-based expiration**: every cached object has a max-age (Cache-Control: max-age=86400). After TTL expires, the edge refetches from origin. Simple but imprecise — content may be stale for up to TTL duration. Use short TTLs (60s) for dynamic content; long TTLs (1 year) for versioned static assets.

- **Purge by URL**: explicitly invalidate specific URLs via CDN API after a content update. Cloudflare, Fastly, and CloudFront all support purge APIs. Latency: a purge propagates to all PoPs in 1-5 seconds. Use for targeted invalidation of a small number of URLs.

- **Cache-busting (versioned URLs)**: embed a content hash in the filename: `app.a3f8b2c.js`. Each deployment generates new filenames. Old files are never explicitly purged — they expire naturally via TTL. New browsers automatically get new content because the URL changed. This is the most reliable approach for static assets.

- **Surrogate keys / cache tags**: tag cached responses with logical keys (product:123, user:456). Purge all responses with a given tag in one API call — useful for purging all pages that show a specific product after its price changes.

## Edge Functions: Cloudflare Workers

Cloudflare Workers run JavaScript (and Rust/WASM) at 300+ PoPs globally, executing within 0-5ms of the user. Workers intercept every request before it reaches the origin, enabling:


```
// Cloudflare Worker: A/B testing at the edge
export default {
    async fetch(request, env) {
        const url = new URL(request.url);

        // Route 10% of users to new checkout
        const userId = request.headers.get("X-User-Id") ?? "";
        const bucket = parseInt(userId.slice(-2), 16) % 100;  // hash to 0-99
        if (bucket < 10 && url.pathname === "/checkout") {
            url.hostname = "checkout-v2.example.com";
            return fetch(new Request(url, request));
        }

        // Serve from cache for static assets
        const cache = caches.default;
        let response = await cache.match(request);
        if (!response) {
            response = await fetch(request);
            if (response.ok && url.pathname.startsWith("/static/")) {
                const toCache = response.clone();
                event.waitUntil(cache.put(request, toCache));
            }
        }
        return response;
    }
};
```


Workers use V8 isolates (not containers) — cold start is <1ms. Each request runs in an isolated JavaScript context with no shared state between requests. Workers KV provides distributed key-value storage readable from any PoP (eventually consistent, 60ms propagation globally). Durable Objects provide strongly consistent, single-instance stateful objects at the edge — useful for rate limiting, presence, and collaborative editing.

## Lambda@Edge vs Cloudflare Workers

| Feature | Cloudflare Workers | Lambda@Edge |
| --- | --- | --- |
| Cold start |
