YouTube is a video-sharing platform where users can upload, watch, and discover videos across a wide range of content categories. It provides tools for creators to publish and monetize their content, while viewers can engage through likes, comments, and subscriptions.
Background: Video Streaming
Video streaming is the process of delivering video content over the internet in a way that allows playback to begin before the entire file has been downloaded. Instead of sending a large video file all at once, the system breaks the video into smaller chunks and delivers them sequentially. This enables users to start watching almost immediately, improving perceived performance and reducing waiting time.
- Bitrate – Bitrate represents the amount of data transmitted per second (e.g., kbps or Mbps). Higher bitrate generally means better quality but requires more bandwidth. Bitrate is influenced by resolution, frame rate (FPS), and compression efficiency, and is a key factor in streaming performance.
- Resolution – Resolution defines the dimensions of a video (e.g., 720p, 1080p, 4K). Higher resolution improves visual clarity but increases file size and bandwidth requirements. Streaming systems often provide multiple resolutions to support different devices and network conditions.
- Frame Rate (FPS) – Frames per second determines how many images are displayed per second. Higher FPS (e.g., 60fps) results in smoother motion but increases data size and processing requirements compared to lower FPS (e.g., 24fps or 30fps).
- Manifest Files – Text-based files (e.g., .m3u8 for HLS or .mpd for DASH) that describe available video streams. They list different quality versions and segment URLs, allowing the player to request and switch between video chunks during playback.
- Video Codec – A codec (encoder/decoder) compresses and decompresses video data to reduce file size while preserving quality. It directly impacts storage cost and streaming efficiency. Common codecs include H.264, H.265 (HEVC), VP9, and AV1, each offering different trade-offs between compression efficiency, compatibility, and computational cost.
Product Requirements
Functional Requirements
- Users should be able to upload and publish videos
- Users should be able to watch videos
Non-Functional Requirements
- The system should prioritize availability over consistency
- The sytem should support streaming videos in low latency even though in bad network environment
- The system should handle hundreds of millions of users and massive volumes of video uploads and views.
- The system should continue functioning even if some components fail - resumable upload
- The system should support uploading and watching large videos
Product Design Setup
Data Model
- User: viewers of youtube or youtube creators
- Video: uploaded by creators and consumed by viewers.
- VideoMetadata: Stores structured information about a video, such as title, description, upload timestamp, creatorId, and references to the underlying media files.
API Design
We start with a POST endpoint that supports uploading videos
POST /upload { Video, VideoMetadata (title, description, etc..) }
Then we need a GET endpoint to retrieve a video
GET /videos/:videoID -> Video