Bird
Raised Fist0
HLDsystem_design~20 mins

Content delivery with CDN in HLD - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
CDN Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Designing a CDN for Global Content Delivery

You need to design a Content Delivery Network (CDN) to serve static images globally with low latency. Which architectural component is essential to reduce the load on the origin server?

ADirect user requests always routed to the origin server
BA single centralized database to store all images
CEdge cache servers located near users to store and serve cached content
DLoad balancer only at the origin server without caching
Attempts:
2 left
💡 Hint

Think about how to reduce repeated requests to the main server by serving content closer to users.

scaling
intermediate
2:00remaining
Handling Traffic Spikes with CDN

Your CDN experiences sudden traffic spikes during a product launch. Which scaling strategy helps maintain performance without overloading origin servers?

AIncrease cache TTL to keep content longer at edge servers
BDisable caching to always fetch fresh content from origin
CReduce the number of edge servers to concentrate traffic
DRoute all traffic through a single data center
Attempts:
2 left
💡 Hint

Consider how caching duration affects origin server load during high traffic.

tradeoff
advanced
2:00remaining
Tradeoff Between Cache Freshness and Latency

In a CDN, what is the main tradeoff when setting a very short cache expiration time (TTL) for dynamic content?

ALower latency but higher origin server load due to frequent cache misses
BHigher latency and lower origin server load
CNo impact on latency or origin server load
DCache never expires, so content is always stale
Attempts:
2 left
💡 Hint

Think about how often the CDN must fetch fresh content from the origin.

🧠 Conceptual
advanced
2:00remaining
Understanding CDN Request Flow

When a user requests a file from a CDN edge server that does not have the file cached, what is the correct sequence of events?

A2,1,3,4
B1,2,3,4
C1,3,2,4
D3,2,1,4
Attempts:
2 left
💡 Hint

Think about the logical order from cache check to serving the user.

estimation
expert
3:00remaining
Estimating CDN Capacity for Video Streaming

You expect 1 million users streaming a 5-minute video simultaneously via CDN. Each video bitrate is 3 Mbps. Estimate the minimum total bandwidth capacity the CDN must support to serve all users without buffering.

AApproximately 1,000 Gbps
BApproximately 500 Gbps
CApproximately 15,000 Gbps
DApproximately 3,000 Gbps
Attempts:
2 left
💡 Hint

Calculate total bandwidth by multiplying users by bitrate, then convert units carefully.

Practice

(1/5)
1. What is the primary purpose of a Content Delivery Network (CDN)?
easy
A. To store user data permanently
B. To cache content closer to users for faster delivery
C. To replace the origin server completely
D. To encrypt all website content

Solution

  1. Step 1: Understand CDN function

    A CDN stores copies of content in multiple locations worldwide to reduce latency.
  2. Step 2: Identify main benefit

    This caching near users speeds up content delivery and reduces load on the origin server.
  3. Final Answer:

    To cache content closer to users for faster delivery -> Option B
  4. Quick Check:

    CDN = caching near users [OK]
Hint: CDN = cache content near users for speed [OK]
Common Mistakes:
  • Thinking CDN replaces origin server
  • Confusing CDN with data storage
  • Assuming CDN encrypts all content
2. Which of the following is the correct sequence when a user requests content served via a CDN?
easy
A. User -> Origin Server -> CDN -> User
B. Origin Server -> User -> CDN
C. User -> CDN -> Origin Server (if needed) -> CDN -> User
D. User -> CDN -> User -> Origin Server

Solution

  1. Step 1: Trace request flow in CDN

    User first contacts the CDN edge server; if content is cached, it responds immediately.
  2. Step 2: Understand cache miss handling

    If content is not cached, CDN fetches it from the origin server, caches it, then serves user.
  3. Final Answer:

    User -> CDN -> Origin Server (if needed) -> CDN -> User -> Option C
  4. Quick Check:

    Request flow = CDN first, origin fallback [OK]
Hint: User hits CDN first, origin only if cache miss [OK]
Common Mistakes:
  • Assuming user contacts origin server first
  • Ignoring CDN cache miss flow
  • Confusing response direction
3. Consider this simplified code snippet representing a CDN cache check:
cache = {"index.html": "content"}
request = "style.css"

if request in cache:
    response = cache[request]
else:
    response = "fetch from origin"
print(response)
What will be printed?
medium
A. fetch from origin
B. KeyError
C. content
D. None

Solution

  1. Step 1: Check if request key exists in cache

    The request is "style.css" which is not in cache keys (only "index.html" exists).
  2. Step 2: Determine else branch execution

    Since request not found, else branch runs, setting response to "fetch from origin".
  3. Final Answer:

    fetch from origin -> Option A
  4. Quick Check:

    Cache miss prints fetch from origin [OK]
Hint: If key missing in cache, else branch runs [OK]
Common Mistakes:
  • Assuming cache returns default value automatically
  • Expecting KeyError without else
  • Confusing cache keys with values
4. A CDN is configured but users report slow content loading. Which of these is the most likely cause?
medium
A. The CDN is caching all content correctly
B. Users have slow internet unrelated to CDN
C. The origin server is down but CDN cache is fresh
D. The CDN edge servers are geographically far from users

Solution

  1. Step 1: Analyze CDN slow delivery causes

    If CDN edge servers are far from users, latency increases, causing slow loading.
  2. Step 2: Evaluate other options

    The CDN is caching all content correctly means caching works, so unlikely cause. The origin server is down but CDN cache is fresh means cache serves content fast. Users have slow internet unrelated to CDN is user-side, not CDN issue.
  3. Final Answer:

    The CDN edge servers are geographically far from users -> Option D
  4. Quick Check:

    Distance to CDN edge affects speed [OK]
Hint: Far CDN edges cause slow delivery [OK]
Common Mistakes:
  • Blaming origin server when cache is fresh
  • Ignoring CDN server location
  • Assuming caching always fixes speed
5. You want to design a CDN system that handles sudden traffic spikes without overloading the origin server. Which combination of strategies is best?
hard
A. Use aggressive caching with long TTL and multiple CDN edge locations
B. Disable caching and let all requests go to origin server
C. Use a single CDN edge server with short TTL caching
D. Serve content only from origin server with load balancer

Solution

  1. Step 1: Understand traffic spike handling

    Long TTL caching reduces origin hits; multiple edges distribute load geographically.
  2. Step 2: Evaluate options for scalability

    Disable caching and let all requests go to origin server and D overload origin server. Use a single CDN edge server with short TTL caching limits caching benefits and single edge risks bottleneck.
  3. Final Answer:

    Use aggressive caching with long TTL and multiple CDN edge locations -> Option A
  4. Quick Check:

    Long TTL + many edges = scalable CDN [OK]
Hint: Long cache + many edges handle spikes best [OK]
Common Mistakes:
  • Disabling caching under traffic spikes
  • Relying on single edge server
  • Ignoring TTL impact on origin load