Design of YouTube
Take a deep dive into YouTube’s design.
High-level design
The high-level design shows how we’ll interconnect the various components we identified in the previous lesson. We have started developing a solution to support the functional and non-functional requirements with this design.
The workflow for the abstract design is provided below:
- The user uploads a video to the server.
- The server stores the metadata and the accompanying user data to the database and, at the same time, hands over the video to the encoder for encoding (see 2.1 and 2.2 in the illustration above).
- The encoder, along with the transcoder, compresses the video and transforms it into multiple resolutions (like 2160p, 1440p, 1080p, and so on). The videos are stored on blob storage (similar to GFS or S3).
- Some popular videos may be forwarded to the CDN, which acts as a cache.
- The CDN, because of its vicinity to the user, lets the user stream the video with low latency. However, CDN is not the only infrastructure for serving videos to the end user, which we will see in the detailed design.
Quiz
Why don’t we upload the video directly to the encoder instead of to the server? Doesn’t the current strategy introduce an additional delay?
API design
Let’s understand the design of APIs in terms of the functionalities we’re providing. We’ll design APIs to translate our feature set into technical specifications. In this case, REST APIs can be used for simplicity and speed purposes. Our API design section will help us understand how the client will request services from the back-end application of YouTube. Let’s develop APIs for each of the following features:
- Upload videos
- Stream videos
- Search videos
- View thumbnails
- Like or dislike videos
- Comment on videos
Upload video
The POST method can upload a video to the /uploadVideo
API:
uploadVideo(user_id, video_file, category_id, title, description, tags, default_language, privacy_settings)
Let’s take a look at the description of the following parameters here.
Parameter | Description |
| This is the user that is uploading the video. |
| This is the video file that the user wants to upload. |
| This refers to the category a video belongs to. Typical categories can be “Entertainment,” “Engineering,” “Science,” and so on. |
| This is the title of the video. |
| This is the description of the video. |
| This refers to the specific topics the content of the video covers. The |
| This is the default language a page will show to the user when the video is streamed. |
| This refers to the privacy of the video. Generally, videos can be a public asset or private to the uploader. |
The video file is broken down into smaller packets and uploaded to the server in order. In case of failure, YouTube can store data for a limited time and resume the upload if the user retries. To understand the concept in detail, read more about
... asynchronous APIs APIs where the server cannot fulfill the request immediately, either because the data is too large or isn’t readily available. In that case, the client gets an immediate