Content Delivery and Edge Computing: CDN, Geo-DNS, and Edge Caching
Design global low-latency systems with CDNs, static and dynamic caching, edge compute, geo-DNS, cache invalidation, and origin protection.
Why Content Delivery Matters
Users are global. If every request travels to one origin region, latency, bandwidth cost, and origin load increase. Content Delivery Networks (CDNs) place caches near users so content can be served from the edge.
Key idea: The fastest request is the one that does not reach your origin.
CDN Request Flow
| Term | Meaning |
|---|---|
| Edge location | CDN point of presence near users |
| Origin | Your server or storage bucket |
| Cache hit | Served from CDN |
| Cache miss | CDN fetches from origin |
| TTL | How long content can be cached |
| Purge | Explicitly remove cached content |
What to Cache
| Content Type | Cache Strategy |
|---|---|
| Hashed static assets | Cache for months or years |
| Images and video | Cache long, transform at edge if needed |
| Public HTML | Short TTL or stale-while-revalidate |
| Public API responses | Short TTL with careful keys |
| Personalized pages | Usually no shared cache |
| Authenticated API | Private cache or no cache |
Cache Headers
Cache-Control: public, max-age=31536000, immutable
Good for content-hashed assets like app.a8f3.js.
Cache-Control: public, max-age=60, stale-while-revalidate=300
Good for public content that can be briefly stale.
Cache-Control: private, no-store
Good for sensitive user-specific responses.
Cache keys must include the right dimensions: If language, device, authorization, or tenant affects output, the cache key must account for it or avoid shared caching.
Edge Caching Strategies
Static Asset Caching
Dynamic Content Acceleration
CDNs can cache dynamic responses for short periods, compress payloads, reuse connections to origin, and route around slow network paths.
Stale-While-Revalidate
This protects user latency and origin load during refreshes.
Cache Invalidation
Invalidation is the hardest operational part of CDN caching.
| Strategy | Use Case |
|---|---|
| Content hashing | Static assets |
| Short TTL | Dynamic public data |
| Purge by URL | Emergency content removal |
| Purge by tag | Product pages, docs, tenant content |
| Versioned paths | API and documentation versions |
Prefer versioned URLs when possible. Purge is useful, but relying on it for every deploy can become fragile.
Geo-DNS and Global Routing
Geo-DNS returns different endpoints based on user location, latency, or health.
| Routing Policy | Best For |
|---|---|
| Geo routing | Data residency and regional products |
| Latency routing | Send users to fastest healthy region |
| Weighted routing | Gradual traffic shifts |
| Failover routing | Disaster recovery |
DNS caching means failover is not always instant. Use low TTLs for records that may need quick movement.
Edge Computing
Edge compute runs code near users. Examples include request rewriting, authentication checks, redirects, A/B assignment, lightweight personalization, and image transformations.
Good Edge Workloads
| Workload | Why It Fits |
|---|---|
| URL redirects | Low latency, simple logic |
| Header normalization | Before cache key selection |
| Bot filtering | Stop bad traffic early |
| A/B routing | Assign before origin |
| Image resize | Avoid origin processing |
| JWT verification | Lightweight authorization at edge |
Poor Edge Workloads
| Workload | Problem |
|---|---|
| Heavy database transactions | Data is not at the edge |
| Long-running jobs | Edge runtimes have limits |
| Complex business workflows | Harder to debug and deploy safely |
| Sensitive writes | Consistency and audit concerns |
Origin Protection
A CDN should reduce origin load and shield it from spikes.
| Technique | Purpose |
|---|---|
| Request coalescing | One origin request for many simultaneous cache misses |
| Shield POP | Central cache layer before origin |
| Rate limiting | Block abusive traffic at edge |
| WAF rules | Filter attacks before origin |
| Bot detection | Reduce unwanted scraping |
| Cache warming | Avoid cold start after deploy |
What to Remember for Interviews
- CDNs reduce latency and origin load: serve cacheable content near users.
- Cache keys matter: vary by dimensions that change the response.
- Static assets should be immutable: content hashes make long TTLs safe.
- Edge compute is for lightweight logic: not heavy workflows.
- Invalidation strategy is part of design: use versioning, TTLs, tags, and purges deliberately.
Practice: Design global content delivery for a video learning platform. Include static assets, video segments, authenticated users, regional routing, edge transforms, and cache invalidation.