Bird
Raised Fist0
HLDsystem_design~7 mins

Media sharing in messages in HLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
When users send media files like photos or videos in messages, directly embedding these large files can cause slow message delivery, increased storage costs, and poor user experience due to long loading times. Without a proper system, the messaging service can become slow, unreliable, and expensive to maintain.
Solution
The system stores media files separately from text messages in a dedicated media storage service. Messages contain references or links to the media instead of the actual files. When a user sends media, the file uploads to the media storage, and the message includes a secure URL. On receiving, the client fetches the media asynchronously, improving message speed and reducing load on the messaging servers.
Architecture
User Client ├────────────────────▶
Media Storage
Media Storage
Messaging
◀────────────────────┤ Media Storage
Receiving
User Client

This diagram shows how the user client uploads media to a media storage service, which stores the file and returns a URL. The messaging service stores the message with the media URL and delivers it to the receiving client, which fetches the media asynchronously.

Trade-offs
✓ Pros
Reduces load on messaging servers by offloading media storage and delivery.
Improves message delivery speed since only text and media URLs are sent initially.
Enables scalable storage solutions optimized for large files like CDN or object storage.
Allows asynchronous media loading on clients, improving user experience.
✗ Cons
Requires additional infrastructure for media storage and CDN integration.
Increases complexity in handling media upload failures and URL expiration.
Needs secure access control to prevent unauthorized media access.
When the system handles large media files frequently and message delivery speed is critical, typically at scale of thousands of concurrent users sharing media.
For simple chat apps with very low media sharing volume (under 100 uploads per day), where added complexity outweighs benefits.
Real World Examples
WhatsApp
Stores media files separately on their servers and sends message references to enable fast message delivery and efficient media handling.
Slack
Uploads files to dedicated storage and shares secure links in messages, allowing asynchronous loading and reducing message payload size.
Discord
Uses CDN-backed media storage for images and videos shared in messages to ensure fast delivery and scalable storage.
Alternatives
Inline media embedding
Media files are embedded directly inside message payloads without separate storage.
Use when: Only for very small media files or systems with extremely low traffic and simple architecture.
Peer-to-peer media sharing
Media files are shared directly between clients without central storage.
Use when: For decentralized apps where server storage is limited or privacy is a priority.
Summary
Separating media storage from message delivery improves performance and scalability.
Messages contain references to media stored in dedicated storage or CDN services.
This approach reduces server load and enables asynchronous media loading on clients.