| Scale | Users | Messages/Day | Media Uploads/Day | Storage Needed | Bandwidth | System Changes |
|---|---|---|---|---|---|---|
| Small | 100 | 10,000 | 2,000 | ~20 GB | ~50 Mbps | Single server, local storage, simple DB |
| Medium | 10,000 | 1,000,000 | 200,000 | ~2 TB | ~500 Mbps | Multiple app servers, CDN for media, DB replicas |
| Large | 1,000,000 | 100,000,000 | 20,000,000 | ~200 TB | ~5 Gbps | Sharded DB, distributed storage, multi-CDN, load balancers |
| Very Large | 100,000,000 | 10,000,000,000 | 2,000,000,000 | ~20 PB | ~50 Gbps+ | Global data centers, advanced sharding, tiered storage, edge caching |
Media sharing in messages in HLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small to medium scale, the database becomes the first bottleneck due to high write and read operations for message metadata and media references.
As user count and media volume grow, storage I/O and network bandwidth for media uploads/downloads become bottlenecks.
Eventually, the media storage system and CDN capacity limit scalability before the app servers.
- Database: Use read replicas and connection pooling to handle increased queries.
- Caching: Cache frequently accessed media metadata and message data to reduce DB load.
- Storage: Move media files to distributed object storage (e.g., S3) with lifecycle policies.
- CDN: Use Content Delivery Networks to serve media closer to users, reducing bandwidth and latency.
- Sharding: Partition database and storage by user or message ID to distribute load.
- Horizontal Scaling: Add more app servers behind load balancers to handle concurrent connections.
- Compression & Thumbnails: Store optimized media versions to save bandwidth and storage.
Assuming 1 million users sending 100 messages/day with 20% containing media:
- Messages/day: 100 million
- Media uploads/day: 20 million
- Average media size: 1 MB -> 20 TB/day storage inflow
- Bandwidth: 20 million uploads + downloads -> ~5 Gbps sustained
- DB QPS: ~10,000 queries per second (writes + reads)
- Storage growth: 20 TB/day -> requires tiered storage and archival
Start by defining scale milestones and expected traffic.
Identify the first bottleneck clearly (usually DB or storage).
Discuss incremental scaling steps: caching, read replicas, CDN, sharding.
Explain trade-offs and how each solution addresses specific bottlenecks.
Keep answers structured: current state, bottleneck, solution, future growth.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement caching to reduce direct DB load before scaling vertically or sharding.
Practice
Solution
Step 1: Understand media file size impact
Media files like photos and videos are large and can slow down message storage if kept together.Step 2: Separate storage benefits
Separating media storage allows using specialized systems like CDNs and cloud storage optimized for large files.Final Answer:
To improve performance and scalability by handling large media files separately -> Option CQuick Check:
Separate media storage = better performance [OK]
- Thinking media size doesn't affect performance
- Confusing UI design with storage design
- Ignoring scalability needs
Solution
Step 1: Identify media delivery needs
Media files are large and need fast delivery to users worldwide.Step 2: Role of CDN
A CDN caches media files close to users, reducing latency and bandwidth usage.Final Answer:
Content Delivery Network (CDN) -> Option AQuick Check:
Fast media delivery = CDN [OK]
- Confusing CDN with database indexing
- Thinking load balancers handle media files
- Ignoring network latency
Solution
Step 1: Understand media upload flow
Media files are large, so they are uploaded separately to cloud storage for efficiency.Step 2: Message stores media reference
The message contains a URL pointing to the media location, not the media itself.Final Answer:
The photo is uploaded to cloud storage and the message stores a URL pointing to it -> Option BQuick Check:
Media URL in message = cloud upload [OK]
- Embedding large media in message text
- Using base64 which increases size
- Storing media in message queues
Solution
Step 1: Identify problem with current design
Storing large media in the database slows down queries and reduces scalability.Step 2: Apply best practice for media storage
Moving media to cloud storage and storing URLs improves performance and scalability.Final Answer:
Move media files to cloud storage and store only URLs in the database -> Option DQuick Check:
Separate media storage = faster queries [OK]
- Relying only on hardware upgrades
- Compressing media but still storing in DB
- Removing media reduces feature, not fix
Solution
Step 1: Analyze scalability needs
Millions of users require scalable storage and fast delivery without overloading servers.Step 2: Choose best architecture components
Cloud storage handles large media files reliably; CDN speeds up delivery globally; storing URLs keeps messages lightweight.Step 3: Evaluate other options
Single server or embedding media causes bottlenecks; peer-to-peer lacks reliability and control.Final Answer:
Upload media to cloud storage, use a CDN for delivery, and store media URLs in messages -> Option AQuick Check:
Cloud storage + CDN + URLs = scalable media sharing [OK]
- Storing media in DB causing bottlenecks
- Sending base64 increases message size
- Ignoring global delivery speed
