0
0
HLDsystem_design~7 mins

CDN concept and usage in HLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
When all user requests go directly to a single origin server, it becomes overloaded, causing slow response times and outages. Users far from the server experience high latency, making the service feel sluggish and unreliable.
Solution
A CDN places copies of content on multiple servers distributed worldwide. When a user requests content, the CDN serves it from the nearest server, reducing load on the origin and speeding up delivery by shortening the distance data travels.
Architecture
Origin
Origin
CDN Edge
Server 1
User A
(Near S1)

This diagram shows an origin server distributing content to multiple CDN edge servers. Users receive content from the nearest CDN edge server, reducing latency and origin load.

Trade-offs
✓ Pros
Reduces latency by serving content from geographically closer servers.
Decreases load on the origin server, improving its stability and scalability.
Improves availability by providing multiple points of presence for content delivery.
Can reduce bandwidth costs by caching popular content at the edge.
✗ Cons
Cache invalidation can be complex, leading to stale content if not managed properly.
Initial setup and integration with origin servers add complexity.
Less effective for highly dynamic or personalized content that cannot be cached.
Use when serving static or cacheable content to a global or widely distributed user base with request rates above 1,000 requests per second.
Avoid when content is highly dynamic and personalized per user, or when the user base is small and localized, making CDN overhead unnecessary.
Real World Examples
Netflix
Uses CDN to cache and deliver video streams from edge servers close to users, reducing buffering and improving playback quality worldwide.
Amazon
Employs CDN to speed up delivery of product images and static assets globally, ensuring fast page loads for shoppers everywhere.
LinkedIn
Uses CDN to serve static resources like images and scripts, reducing load on core servers and improving user experience across regions.
Alternatives
Origin Pull with Cache-Control Headers
Relies on browsers and intermediate proxies to cache content rather than a distributed network of edge servers.
Use when: When user base is small or regional and deploying a full CDN is not cost-effective.
Peer-to-Peer Content Delivery
Uses users' devices to share content directly, reducing server load without centralized edge servers.
Use when: When distributing large files like software updates where users can share data among themselves.
Summary
CDNs distribute content across multiple edge servers to reduce latency and origin load.
They improve user experience by serving content from locations closer to users worldwide.
CDNs are best for static or cacheable content and large, distributed user bases.