DevPrep
  • Interview Prep
  • Projects
  • Resources
  • Pricing
  • About Us
Submit Question
DevPrep
  • Pricing
  • About Us
Submit Question
← From Beginner to Expert in Fundamentals of Frontend
  • How the Web Works
  • Browsers: The Engines
  • Networking & Latency
  • HTTPS & TLS Handshake
  • CDNs & Edge Computing
  • WebSockets & WebRTC
  • RESTful Architecture
  • GraphQL Architecture
  • CORS (Cross-Origin Resource Sharing)
  • Load Balancing
  • Critical Rendering Path Deep Dive
  • DOM vs. CSSOM Construction
  • The Rendering Engine: Layout, Paint, Compositing
  • JavaScript Engine: V8 Internals
  • The Event Loop: Macro vs. Micro Tasks
  • Garbage Collection
  • Browser Storage Architecture
  • Service Workers & PWAs
  • Web Workers: Multi-Threading
← From Beginner to Expert in Fundamentals of Frontend

CDNs & Edge Computing

18 min read
CDNEdge ComputingCache InvalidationPoPOrigin ServerTTL

Content Delivery Networks: Bringing Your App Closer to Users

A CDN is a globally distributed network of servers (called Points of Presence or PoPs) that cache and serve your content from the location closest to each user.

How CDNs Work

  1. First Request: User in Tokyo requests your site. The CDN's DNS routes them to the nearest PoP (e.g., Tokyo edge server).
  2. Cache Miss: The edge server doesn't have the content yet. It fetches from your Origin Server (e.g., in US-East), caches it, and serves it.
  3. Subsequent Requests: Any user in the Tokyo region gets the cached version — no round-trip to the US needed.

Caching Strategies

StrategyHeaderUse Case
Cache ForeverCache-Control: max-age=31536000, immutableHashed static assets (app.a1b2c3.js)
RevalidateCache-Control: no-cacheHTML pages (check freshness each time)
Never CacheCache-Control: no-storePersonalized/sensitive data
Stale While RevalidateCache-Control: max-age=60, stale-while-revalidate=3600API responses that can be slightly stale

Edge Computing vs. Traditional CDN

Traditional CDNs just cache static files. Edge computing (Cloudflare Workers, Vercel Edge Functions) runs your code at the edge — enabling personalization, A/B testing, and geolocation logic without hitting the origin.

Cache Invalidation — The Hardest Problem

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

When you deploy a new version, you need to purge the CDN cache. Strategies include:

  • Cache Busting: Add content hashes to filenames (Webpack/Vite do this automatically).
  • Purge API: Programmatically invalidate specific URLs via CDN API.
  • Tag-based Invalidation: Tag cached responses (e.g., "product-123") and purge by tag.

Key Metrics

  • Cache Hit Ratio: Percentage of requests served from cache (target: >90%).
  • TTFB (Time to First Byte): Should be <100ms for cached content.
  • Origin Shield: A secondary cache layer that protects your origin from thundering herd problems.

Practice

  • JavaScript
  • DSA
  • Machine Coding
  • System Design

Resources

  • Learning Tracks
  • Articles
  • Roadmaps
  • Compare Concepts
  • Glossary
  • Developer Tools
  • All Questions

Company

  • About
  • Pricing

Legal

  • Privacy Policy
  • Terms of Service
DevPrep

© 2026 DevPrep. All rights reserved.