Bird
Raised Fist0
Interview Prepcomputer-networksmediumAmazonGoogleFlipkartSwiggyPhonePeZeptoRazorpay

CDN - How Content Delivery Networks Work, Edge Caching

Choose your preparation mode2 modes available
🎯
CDN - How Content Delivery Networks Work, Edge Caching
mediumNETWORKSAmazonGoogleFlipkart

Imagine streaming a live cricket match from India to millions of viewers worldwide without buffering delays or server crashes.

💡 Beginners often confuse CDNs with just caching proxies or think CDNs only replicate content without understanding the dynamic routing and caching strategies involved.
📋
Interview Question

Explain how Content Delivery Networks (CDNs) work, focusing on the role of edge caching and how it reduces latency for end users.

Edge servers and origin serversCaching and Time-To-Live (TTL)Geo-routing and latency optimization
💡
Scenario & Trace
ScenarioA user in New York requests a popular video hosted on a server in California.
1. User sends HTTP request → 2. DNS resolves to nearest CDN edge server in New York → 3. Edge server checks cache for video → 4. If cached and TTL valid, edge server serves video directly → 5. If not cached or TTL expired, edge server fetches video from origin server in California → 6. Edge caches the video and serves user → 7. Subsequent nearby users get video from edge cache, reducing latency and load on origin.
ScenarioA new product image is updated on an e-commerce site’s origin server.
1. Origin server updates image → 2. Edge servers still have old cached image with TTL not expired → 3. User requests image from edge server → 4. Edge serves stale image until TTL expires or cache is purged → 5. After TTL expiry or purge, edge fetches updated image from origin → 6. Users then see the updated image.
  • What happens if two edge servers have inconsistent cached versions due to TTL differences?
  • How does CDN handle cache misses when the origin server is temporarily unreachable?
  • What if a user is located in a region with no nearby edge servers?
⚠️
Common Mistakes
Thinking CDN is just a caching proxy without geo-distribution

Interviewer doubts your understanding of CDN scale and latency optimization

Emphasize the global distribution of edge servers and geo-routing

Assuming cached content is always fresh and instantly updated

Interviewer questions your grasp of TTL and cache invalidation

Explain TTL, cache expiry, and purging mechanisms that balance freshness and performance

Ignoring what happens on cache misses or origin failures

Interviewer suspects you don't understand CDN fault tolerance

Discuss fallback to origin, error handling, and retry strategies

Confusing CDN with DNS or load balancers alone

Interviewer thinks you lack clarity on CDN components

Clarify that DNS and load balancing are part of CDN routing but CDN includes caching and edge servers

🧠
Basic Definition - What It Is
💡 This is the minimum you must know to explain CDNs in a simple interview setting.

Intuition

A CDN is a network of servers distributed globally to deliver content faster by caching it closer to users.

Explanation

Content Delivery Networks (CDNs) are systems of geographically distributed servers that cache copies of content from an origin server. When a user requests content, the CDN directs the request to the nearest edge server, which serves the cached content if available. This reduces the distance data travels, lowering latency and improving load times. Edge caching means storing content temporarily on these edge servers with a validity period called TTL (Time-To-Live). If the cached content is fresh, it is served directly; otherwise, the edge server fetches updated content from the origin.

Memory Hook

💡 Think of a CDN like a chain of local libraries (edge servers) stocked with popular books (content) so readers (users) don’t have to travel to the main library (origin server) far away.

Illustrative Code

# No code for this conceptual approach
# Explanation focused, no implementation needed

Interview Questions

What is the primary purpose of a CDN?
  • Reduce latency by caching content closer to users
  • Decrease load on origin servers
What role does TTL play in edge caching?
  • Defines how long cached content is considered fresh
  • Controls when edge server fetches updated content from origin
Depth Level
Interview Time30 seconds
Depthbasic

This approach is conceptual and does not involve algorithmic complexity. It covers fundamental understanding suitable for screening or quick conceptual questions.

Interview Target: Minimum floor - never go below this

Knowing only this will help you pass initial screening but is insufficient for deeper technical discussions.

🧠
Mechanism Depth - How It Works
💡 This is what product companies expect for on-site interviews and deeper understanding.

Intuition

CDNs use geo-routing to direct user requests to the optimal edge server, which caches content with TTL and fetches from origin on cache misses or expiry, balancing freshness and latency.

Explanation

A CDN operates by deploying multiple edge servers strategically across geographic locations. When a user requests content, DNS or HTTP redirection mechanisms route the request to the nearest or best-performing edge server based on latency, load, and network conditions (geo-routing). The edge server checks its cache for the requested content. If the content is cached and the TTL has not expired, it serves the content immediately, minimizing latency. If the content is missing or stale, the edge server fetches the latest version from the origin server, caches it, and then serves the user. This caching strategy reduces bandwidth usage and origin load. CDNs also handle cache invalidation through TTL expiry or explicit purging to ensure content freshness. Additionally, CDNs implement fallback mechanisms for origin unavailability and optimize routing to handle users in regions without nearby edge servers.

Memory Hook

💡 Imagine a relay race where runners (edge servers) pass the baton (content) quickly to the next runner closest to the finish line (user), but occasionally must run back to the start (origin) to get a fresh baton when theirs expires.

Illustrative Code

# No code for this conceptual approach
# Explanation focused, no implementation needed

Interview Questions

How does geo-routing improve CDN performance?
  • Routes user requests to nearest or fastest edge server
  • Reduces latency and network congestion
What happens on a cache miss at the edge server?
  • Edge server requests content from origin
  • Caches the content for future requests
  • Serves content to user after fetching
How does TTL affect content freshness and CDN efficiency?
  • Short TTL improves freshness but increases origin load
  • Long TTL reduces origin load but risks stale content
Depth Level
Interview Time2-3 minutes
Depthintermediate

This approach is conceptual and does not involve algorithmic complexity. It demonstrates understanding of CDN internals, trade-offs, and real-world operation.

Interview Target: Target level for FAANG on-sites

Mastering this level distinguishes you from most candidates and prepares you for follow-up questions.

📊
Explanation Depth Levels
💡 Choose your explanation depth based on interview stage and company expectations.
LevelInterview TimeSuitable ForRisk
Basic Definition30sScreening call or quick conceptual questionsToo shallow for on-site or technical deep dives
Mechanism Depth2-3 minutesOn-site interviews at product companies like FAANGRequires good understanding; missing details may lead to follow-up questions
💼
Interview Strategy
💡 Use this guide to structure your explanation clearly and confidently before every mock or real interview.

How to Present

Start with a concise definition of what a CDN is and its purpose.Give a relatable example or analogy to make the concept tangible.Explain the internal mechanism focusing on edge caching, TTL, and geo-routing.Discuss common edge cases and how CDNs handle them.

Time Allocation

Definition: 30s → Example: 1min → Mechanism: 2min → Edge cases: 30s. Total ~4min

What the Interviewer Tests

Interviewer checks your clarity on CDN purpose, caching mechanics, latency reduction, and handling of cache freshness and failures.

Common Follow-ups

  • How do CDNs handle dynamic content that changes frequently? → Use cache bypass or short TTL.
  • What strategies exist for cache invalidation? → TTL expiry, purging, versioning.
💡 These follow-ups test your knowledge of CDN limitations and advanced features.
🔍
Pattern Recognition

When to Use

Asked when interviewers want to assess understanding of web performance, scalability, and distributed systems.

Signature Phrases

Explain how a CDN worksWhat is edge caching?How does TTL affect CDN performance?

NOT This Pattern When

Similar Problems