0
0
HLDsystem_design~7 mins

CDN caching for static content in HLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
When all user requests for static files like images, stylesheets, or scripts hit the origin server, it becomes overloaded, causing slow response times and potential downtime. Users far from the origin also experience high latency, leading to poor user experience.
Solution
A Content Delivery Network (CDN) caches static content on servers distributed globally. When a user requests a static file, the CDN serves it from the nearest cache server, reducing load on the origin and speeding up delivery by minimizing network distance.
Architecture
Origin
Origin
CDN
CDN
User A
(Near CDN

This diagram shows user requests for static content being served by CDN edge servers close to users, reducing load on the origin server and improving response times.

Trade-offs
✓ Pros
Reduces load on origin servers by serving cached static content from CDN edge servers.
Improves user experience by lowering latency through geographically closer servers.
Scales easily to handle large traffic spikes without origin server overload.
Offloads bandwidth costs from origin to CDN providers.
✗ Cons
Cache invalidation can be complex, leading to stale content if not managed properly.
Additional cost for CDN services compared to serving directly from origin.
Initial cache miss causes a request to origin, which can add latency for first-time content.
Use when your system serves significant static content to a geographically distributed user base and experiences high traffic or latency issues.
Avoid if your traffic is very low (e.g., under 100 requests per second) or if content changes too frequently making caching ineffective.
Real World Examples
Netflix
Uses CDN caching to deliver static assets like images and UI scripts quickly worldwide, reducing load on central servers and improving streaming startup times.
Amazon
Caches product images and static web assets on CDN edge servers to provide fast page loads globally and reduce origin server bandwidth.
Shopify
Delivers static storefront assets via CDN to ensure merchants’ sites load quickly for customers anywhere in the world.
Alternatives
Origin Pull with Cache-Control Headers
Relies on browsers and intermediate caches to store static content rather than a global CDN network.
Use when: When you have a smaller user base mostly in one region and want to avoid CDN costs.
Edge Computing with Dynamic Content Caching
Caches not only static but also dynamic content at edge servers with logic to update caches dynamically.
Use when: When you need to cache personalized or frequently changing content closer to users.
Summary
CDN caching reduces origin server load by serving static content from globally distributed edge servers.
It improves user experience by lowering latency and handling traffic spikes efficiently.
Proper cache management is essential to avoid stale content and balance cost versus performance.