Bird
Raised Fist0
HLDsystem_design~7 mins

Media storage and CDN in HLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
When a website or app serves media files like images or videos directly from a single storage server, users far from that server experience slow loading times. High traffic spikes can overload the storage server, causing delays or failures in delivering media content.
Solution
Media files are stored in a scalable storage system optimized for large files. A Content Delivery Network (CDN) caches copies of these files in servers distributed worldwide. When a user requests media, the CDN serves it from the nearest cache, reducing latency and load on the main storage.
Architecture
User 1
(Location A)
CDN Edge Node
User 2
(Location B)
CDN Edge Node

This diagram shows users from different locations requesting media files. The CDN edge nodes cache media close to users, reducing direct requests to the central media storage.

Trade-offs
✓ Pros
Reduces latency by serving media from geographically closer servers.
Decreases load on the origin media storage, improving scalability.
Improves availability by serving cached content even if origin is temporarily unreachable.
✗ Cons
Cache invalidation can be complex, leading to stale content if not managed properly.
Initial cache misses cause requests to hit the origin, which may cause latency spikes.
Costs increase due to CDN usage and data transfer fees.
When your system serves large media files to a global user base with high read traffic exceeding thousands of requests per second.
When your user base is small and localized, or media files are rarely accessed, making CDN overhead unjustified.
Real World Examples
Netflix
Uses CDN to cache and deliver video streams close to users worldwide, reducing buffering and improving playback quality.
Amazon
Delivers product images and videos via CDN to ensure fast page loads globally during high traffic events like Prime Day.
Spotify
Caches album art and audio files on CDN edge servers to reduce latency and server load during peak usage.
Alternatives
Direct Origin Serving
All media requests go directly to the central storage without caching or distribution.
Use when: When traffic is low and user locations are concentrated near the storage server.
Peer-to-Peer (P2P) Distribution
Users share media files directly with each other, reducing load on central servers.
Use when: When building decentralized systems or when bandwidth costs must be minimized.
Summary
Serving media directly from a single server causes slow load times and overloads under high traffic.
CDNs cache media files on servers near users to reduce latency and origin load.
Proper cache management and origin scalability remain essential for reliable media delivery.