Scalability & Performance

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.

CDNedge computinggeo-DNScache invalidationCloudflare

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

TermMeaning
Edge locationCDN point of presence near users
OriginYour server or storage bucket
Cache hitServed from CDN
Cache missCDN fetches from origin
TTLHow long content can be cached
PurgeExplicitly remove cached content

What to Cache

Content TypeCache Strategy
Hashed static assetsCache for months or years
Images and videoCache long, transform at edge if needed
Public HTMLShort TTL or stale-while-revalidate
Public API responsesShort TTL with careful keys
Personalized pagesUsually no shared cache
Authenticated APIPrivate cache or no cache

Cache Headers

http
Cache-Control: public, max-age=31536000, immutable

Good for content-hashed assets like app.a8f3.js.

http
Cache-Control: public, max-age=60, stale-while-revalidate=300

Good for public content that can be briefly stale.

http
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.

StrategyUse Case
Content hashingStatic assets
Short TTLDynamic public data
Purge by URLEmergency content removal
Purge by tagProduct pages, docs, tenant content
Versioned pathsAPI 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 PolicyBest For
Geo routingData residency and regional products
Latency routingSend users to fastest healthy region
Weighted routingGradual traffic shifts
Failover routingDisaster 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

WorkloadWhy It Fits
URL redirectsLow latency, simple logic
Header normalizationBefore cache key selection
Bot filteringStop bad traffic early
A/B routingAssign before origin
Image resizeAvoid origin processing
JWT verificationLightweight authorization at edge

Poor Edge Workloads

WorkloadProblem
Heavy database transactionsData is not at the edge
Long-running jobsEdge runtimes have limits
Complex business workflowsHarder to debug and deploy safely
Sensitive writesConsistency and audit concerns

Origin Protection

A CDN should reduce origin load and shield it from spikes.

TechniquePurpose
Request coalescingOne origin request for many simultaneous cache misses
Shield POPCentral cache layer before origin
Rate limitingBlock abusive traffic at edge
WAF rulesFilter attacks before origin
Bot detectionReduce unwanted scraping
Cache warmingAvoid cold start after deploy

What to Remember for Interviews

  1. CDNs reduce latency and origin load: serve cacheable content near users.
  2. Cache keys matter: vary by dimensions that change the response.
  3. Static assets should be immutable: content hashes make long TTLs safe.
  4. Edge compute is for lightweight logic: not heavy workflows.
  5. 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.