Content Delivery Networks (CDN) in Computer Networks - Time & Space Complexity
When studying CDNs, it is important to understand how the time to serve content changes based on the number of users, edge servers, and cached items.
We want to know how cache lookup and content retrieval scale as CDN infrastructure grows.
Analyze the time complexity of the following simplified CDN cache lookup process.
for each incoming_request in requests:
cache_key = hash(request.url)
if cache_key in edge_cache:
return edge_cache[cache_key]
else:
content = fetch_from_origin(request.url)
edge_cache[cache_key] = content
return content
This code processes each user request by computing a hash of the URL, checking the edge cache, and either returning cached content or fetching from the origin.
Look at the operations performed for each request.
- Primary operation: Hash computation and cache lookup for each request.
- How many times: Once per incoming request. The cache lookup itself is a hash table operation.
As the number of requests grows, the total work increases linearly, but each individual lookup remains constant time.
| Input Size (n requests) | Cache Lookups | Origin Fetches (worst case) |
|---|---|---|
| 100 requests | 100 (O(1) each) | 100 (all unique URLs) |
| 1,000 requests | 1,000 (O(1) each) | ~200 (most are cache hits) |
| 10,000 requests | 10,000 (O(1) each) | ~500 (high cache hit rate) |
Pattern observation: Cache lookups scale linearly with requests, but origin fetches grow much slower because repeated URLs are served from cache. The cache hit ratio improves as more content gets cached.
Time Complexity: O(n) for processing n requests
Each request requires O(1) for the hash computation and cache lookup. Processing n total requests takes O(n) time. The key insight is that origin fetches (the expensive operation) decrease as the cache warms up.
[X] Wrong: "Every request requires fetching from the origin server, so the time grows with both requests and content size."
[OK] Correct: The entire purpose of a CDN cache is to avoid origin fetches. After the first request for a URL caches the content, all subsequent requests for the same URL are O(1) cache hits. The origin fetch only happens once per unique URL.
Understanding CDN cache lookup complexity helps explain why CDNs can handle millions of requests per second. Each edge server performs O(1) lookups, and the distributed nature means total capacity scales linearly with the number of edge servers.
What if the cache has a fixed size and uses LRU eviction? How would the cache hit rate change for a CDN serving a long-tail distribution of URLs where a few URLs get most traffic?
Practice
Solution
Step 1: Understand CDN's role in content delivery
A CDN stores copies of website content on servers around the world to reduce the distance data travels.Step 2: Identify the main benefit of CDN
This reduces load on the main server and speeds up content delivery to users globally.Final Answer:
To store copies of content on multiple servers worldwide to speed up delivery -> Option BQuick Check:
CDN purpose = content caching and faster delivery [OK]
- Thinking CDN creates new content
- Believing CDN replaces main server
- Confusing CDN with encryption service
Solution
Step 1: Define edge server role in CDN
Edge servers cache content near users to reduce the time it takes to load data.Step 2: Eliminate incorrect options
Edge servers do not store only original content, handle authentication, or replace DNS servers.Final Answer:
It caches content closer to users to reduce latency -> Option DQuick Check:
Edge server = caches content near users [OK]
- Confusing edge servers with main data center
- Assuming edge servers handle authentication
- Thinking edge servers replace DNS
Solution
Step 1: Understand cache miss in CDN
If the edge server does not have the requested content, it must get it from the origin server.Step 2: Describe caching after fetch
After fetching, the edge server caches the content to serve future requests faster.Final Answer:
The edge server fetches the file from the origin server and caches it -> Option CQuick Check:
Cache miss = fetch from origin + cache [OK]
- Thinking edge server returns error on cache miss
- Assuming user is redirected to another edge server
- Believing edge server compresses request instead
Solution
Step 1: Analyze CDN coverage impact
If edge servers are missing near certain regions, content must travel farther, causing delays.Step 2: Rule out other causes
Origin server down affects all users, slow internet is user-side, and encryption does not cause major delays.Final Answer:
The CDN has no edge servers near those regions -> Option AQuick Check:
Missing edge servers = slow regional load [OK]
- Blaming origin server when issue is regional
- Ignoring CDN edge server distribution
- Assuming encryption causes slow loading
Solution
Step 1: Identify key CDN strategies for video streaming
Many edge servers reduce latency globally; cache invalidation keeps content fresh.Step 2: Evaluate other options
Single origin server causes bottlenecks; no caching wastes bandwidth; disabling caching hurts performance.Final Answer:
Use many edge servers worldwide and implement cache invalidation policies -> Option AQuick Check:
Global edges + cache control = best scalability [OK]
- Relying on single origin server only
- Not caching large video files
- Disabling caching entirely
Ready to prove it?
Pass the test and this pattern moves unknown
