⬅ Previous Topic
Design WhatsApp - System Design for Messaging ApplicationsNext Topic ⮕
Monitoring and Logging in System Design⬅ Previous Topic
Design WhatsApp - System Design for Messaging ApplicationsNext Topic ⮕
Monitoring and Logging in System DesignYouTube is one of the most popular video-sharing platforms in the world. It allows users to upload, stream, comment on, and search for videos. Designing such a system is a classic system design interview question that tests your understanding of storage, bandwidth, scalability, and user experience.
When a user uploads a video, the frontend sends the video file to a backend server. This server stores the file temporarily and sends it to a storage service (e.g., Amazon S3 or Google Cloud Storage).
Answer: Video files are large binary files. Storing them in a database (like MySQL or PostgreSQL) would slow it down and increase backup/restore complexity. Instead, we store metadata in the database and the actual video in a distributed object storage service.
After uploading, the video must be transcoded into different resolutions (144p, 360p, 720p, 1080p). This is important to support various devices and internet speeds.
Transcoding is usually done using a job queue. For example:
VideoProcessingQueue
.Answer: The system should implement retries and send alerts. Failed jobs are usually logged and stored in a dead-letter queue for manual or automated reprocessing.
The actual videos are stored in object storage (like Amazon S3). Only a reference (URL or ID) is stored in the database along with metadata:
To serve videos efficiently across the globe, we use a Content Delivery Network (CDN). When a user requests a video, the system serves it from the nearest CDN edge location.
Answer: The CDN will fetch it from the origin (e.g., main storage bucket) and cache it at the edge for future users.
We don’t download the full video at once. Instead, we stream it in chunks using HLS (HTTP Live Streaming) or MPEG-DASH protocols. The video is split into tiny segments (e.g., 2–10 seconds long).
For search, we need to index the metadata (title, tags, etc.) using a search engine like Elasticsearch. For recommendations, YouTube uses collaborative filtering and machine learning models.
For beginners, we can implement a rule-based recommendation system:
These features involve separate microservices:
Answer: No. They should write to their own databases. A separate batch job or event system can aggregate the data for analytics and update the video stats periodically.
Let’s look at a simplified video metadata schema:
Table: Videos
-------------
video_id (PK)
uploader_id (FK)
title
description
tags
upload_time
status
video_url
⬅ Previous Topic
Design WhatsApp - System Design for Messaging ApplicationsNext Topic ⮕
Monitoring and Logging in System DesignYou can support this website with a contribution of your choice.
When making a contribution, mention your name, and programguru.org in the message. Your name shall be displayed in the sponsors list.