What is a content delivery network (CDN) and how does it reduce latency?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid System Design basics — a prerequisite for any developer role.
Answer
A CDN reduces latency by serving content from servers geographically closer to the user, reducing the number of network hops and physical distance data must travel. The speed of light imposes a hard limit — data from New York to Tokyo takes ~70ms just for the round-trip light travel time, regardless of server speed. A Tokyo CDN edge serves content in <5ms. Latency reduction mechanisms: (1) Geographic proximity: edge servers in 50-200+ cities worldwide — serve from the nearest one; (2) TCP connection optimization: pre-established persistent connections from edge to origin; edge handles TCP handshake with user (3-way handshake overhead is local); (3) Protocol optimization: CDNs use HTTP/2 or HTTP/3 (QUIC) by default — multiplexing, header compression, faster connection establishment; (4) Reduced origin load: cache hits at edge don't reach origin — origin only handles cache misses; (5) DNS-based routing: CDN DNS returns the IP of the nearest edge node; (6) Anycast routing: same IP address announced from multiple locations — BGP routes to the nearest one. Cache hierarchy: browser cache → CDN edge → CDN regional cache (shield) → origin server. The shield layer reduces origin requests further. Dynamic CDN: CDNs like Fastly and Cloudflare support edge computing (Cloudflare Workers, Fastly Compute@Edge) — run custom code at the edge, enabling dynamic personalization with minimal latency.
Pro Tip
This topic has System Design-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.
Previous
What is the difference between horizontal and vertical scaling?
Next
What is the difference between a monolithic and microservices architecture?