How DNS and CDN work in large-scale systems
DNS resolution, CDN caching, edge nodes, cache-control headers, origin server, TTL, geographic routing
DNS as a Load Balancer
Before a request reaches your servers, DNS resolves your domain to an IP. For large systems, DNS itself can route traffic — returning different IPs based on the client's geographic region (GeoDNS).
What a CDN Does
A CDN (Content Delivery Network) caches static assets at edge nodes geographically close to users. Instead of a Tokyo user fetching a video from your US-East origin server (150ms RTT), they fetch from a Tokyo edge node (5ms RTT).
Cache-Control Headers
# Tell CDN to cache for 1 year
Cache-Control: public, max-age=31536000, immutable
# Tell CDN never to cache (dynamic content)
Cache-Control: no-store
# Cache but revalidate
Cache-Control: no-cacheWhen to Use a CDN
- Static assets: images, JS/CSS bundles, fonts, videos
- Large file downloads
- Any content that doesn't change per user
CDNs don't help with dynamic, personalized content (user feeds, API responses with auth). For those, you need application-level caching closer to your database.
In system design interviews, add a CDN as soon as a global user base is mentioned. It's an easy win with no architectural complexity cost.
