Bird
Raised Fist0
Interview Prepcomputer-networksmediumAmazonGoogleFlipkartSwiggyPhonePeZeptoRazorpay

CDN - How Content Delivery Networks Work, Edge Caching

Choose your preparation mode3 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

Practice

(1/5)
1. Trace the sequence of events when a client sends a request to a web server protected by a reverse proxy. Which step happens immediately after the reverse proxy receives the client request?
easy
A. The reverse proxy forwards the request to the backend server
B. The firewall inspects and blocks the request if malicious
C. The proxy server caches the response for future requests
D. The client directly connects to the backend server

Solution

  1. Step 1: Understand reverse proxy role

    Reverse proxy acts as an intermediary on the server side, receiving client requests first.
  2. Step 2: After receiving the request

    The reverse proxy forwards the request to the backend server for processing.
  3. Step 3: Other options

    Firewall inspection happens before the reverse proxy in the network path; proxy caching is client-side; client does not connect directly to backend when reverse proxy is used.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Reverse proxy forwards request to backend server immediately after receiving it [OK]
Hint: Reverse proxy forwards requests to backend servers.
Common Mistakes:
  • Assuming firewall acts after reverse proxy
  • Confusing proxy caching with reverse proxy behavior
2. You are designing a live video streaming app where minimal delay is critical, and occasional frame loss is acceptable. Which transport protocol is most suitable?
easy
A. TCP, because it uses congestion control to avoid packet loss
B. TCP, because it guarantees delivery and order of packets
C. UDP, because it provides faster transmission without waiting for acknowledgments
D. UDP, because it establishes a connection before sending data

Solution

  1. Step 1: Identify the key requirement -- minimal delay with acceptable occasional loss

    Live video streaming prioritizes speed over perfect reliability.
  2. Step 2: Analyze TCP characteristics

    TCP guarantees delivery and order but introduces delay due to acknowledgments and retransmissions.
  3. Step 3: Analyze UDP characteristics

    UDP is connectionless and does not wait for acknowledgments, enabling faster transmission at the cost of possible packet loss.
  4. Step 4: Evaluate options

    UDP, because it provides faster transmission without waiting for acknowledgments correctly matches the scenario needs. TCP options prioritize reliability over speed. UDP does not establish a connection before sending data, so that option is incorrect.
  5. Final Answer:

    Option C -> Option C
  6. Quick Check:

    UDP is preferred for real-time applications where speed matters more than reliability.
Hint: Use UDP for speed when some loss is okay; TCP for reliability when loss is not acceptable.
Common Mistakes:
  • Assuming TCP is always better because it guarantees delivery
  • Believing UDP establishes a connection like TCP
  • Confusing congestion control with speed priority
3. Which of the following statements about TCP congestion control using AIMD is INCORRECT?
medium
A. AIMD guarantees zero packet loss in all network conditions
B. Multiplicative decrease halves the congestion window upon detecting packet loss
C. Additive increase means the congestion window grows by a fixed amount each RTT
D. AIMD balances efficient bandwidth use with network stability

Solution

  1. Step 1: Verify additive increase meaning

    Congestion window increases by a fixed increment per RTT, which is correct.
  2. Step 2: Confirm multiplicative decrease behavior

    On loss detection, TCP halves the congestion window, consistent with multiplicative decrease.
  3. Step 3: Assess AIMD guarantees

    AIMD does not guarantee zero packet loss; it aims to reduce loss by controlling sending rate.
  4. Step 4: Understand AIMD's balance goal

    AIMD is designed to balance throughput and network stability, which is true.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    AIMD reduces but does not eliminate packet loss.
Hint: AIMD controls congestion but cannot prevent all packet loss.
Common Mistakes:
  • Believing AIMD eliminates all packet loss
  • Misunderstanding additive increase as exponential growth
  • Confusing multiplicative decrease with complete stop
4. If you have a network 10.0.0.0/8 and need to create subnets that support at least 1000 hosts each, which subnet mask would be the most appropriate and why?
hard
A. /22 because it provides 1022 usable hosts per subnet, balancing size and address waste
B. /24 because it is the default Class C mask and easy to manage
C. /20 because it provides 4094 usable hosts per subnet, which is more than needed but efficient
D. /30 because it minimizes IP address waste by creating very small subnets

Solution

  1. Step 1: Calculate hosts per subnet for candidate masks

    /22 mask -> 32 - 22 = 10 host bits -> 2^10 = 1024 addresses - 2 = 1022 usable hosts
  2. Step 2: Check /24 mask

    /24 -> 8 host bits -> 254 usable hosts, insufficient for 1000 hosts
  3. Step 3: Check /20 mask

    /20 -> 12 host bits -> 4094 usable hosts, more than needed but wastes addresses
  4. Step 4: Check /30 mask

    /30 -> 2 host bits -> 2 usable hosts, far too small
  5. Step 5: Choose best fit

    /22 provides just enough hosts with minimal waste, balancing efficiency and requirements.
  6. Final Answer:

    Option A -> Option A
  7. Quick Check:

    Subnet mask must provide ≥1000 hosts; /22 is minimal mask meeting this [OK]
Hint: Hosts per subnet = 2^(32 - mask) - 2
Common Mistakes:
  • Choosing default masks without considering host requirements
  • Picking too large subnets causing address waste
  • Selecting very small subnets ignoring host count needs
5. If a new network protocol requires encryption and compression before data transmission, which TCP/IP model layer would be the best place to implement these features to maintain compatibility and efficiency?
hard
A. Network Interface Layer, since it deals with physical transmission
B. Transport Layer, because it manages data segmentation and reliability
C. Internet Layer, as it routes packets across networks
D. Application Layer, since it handles end-user protocols and data formatting

Solution

  1. Step 1: Identify layer responsibilities relevant to encryption and compression

    Encryption and compression are data transformations related to how data is presented and formatted for applications, which fits the Application Layer's role in TCP/IP (combining OSI's Application, Presentation, and Session layers).
  2. Step 2: Why not other layers?

    Transport Layer manages segmentation and reliability, not data formatting. Internet Layer handles routing, not data content. Network Interface Layer deals with physical transmission, not data processing.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Application Layer is the correct place for encryption/compression to maintain compatibility [OK]
Hint: Encryption/compression belong at Application Layer in TCP/IP
Common Mistakes:
  • Placing encryption at Transport Layer (confusing with TLS)
  • Thinking Internet Layer handles data content
  • Assuming Network Interface Layer manages data transformations
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard