Storing and processing videos for all formats and resolutions.
Different people have different internet connection speeds so if you have a really good internet connection and you can deal with a really difficult format where the data loss is minimum then you can go for a high-quality format. Similarly, there are medium and low-quality video formats also. All these are codecs (A codec is a way in which you compress video).
A single video can have multiple formats and multiple resolutions. And they are making pairs. So number of videos that we need to store are F * R where F = Number of formats and R = Number of resolutions.
Suppose there was a new method to store videos more efficiently. How do we convert the old videos?
Converting the videos will take some time. So we do not want to give the responsibility to a single computer because it will take much more time and there is a chance of failing. Instead, we break the videos into chunks. And then each chunk runs through different resolutions and different formats. This allows us to deal with chunks effectively per processor. At the end of this process, we have chunks for every format and resolution
Let's look at how Netflix processes the chunks in detail
Initially, the entire video file was broken into chunks of equal size. It looks good because every processor is doing the same amount of work. However, this process can lead to a bad user experience.
Consider the case below
The video is divided into chunks of 3 minutes each. In the third minute, there is an action sequence so users want to experience this scene without any buffering. But since we have a chunk at the third minute we need to make an API call and there is a lag.
To overcome this issue, what Netflix ended up doing is not breaking the video into chunks of equal length but based on scenes. Video is broken down into much more fine-grained parts (the size of each part is at most a few seconds) which is called a shot. And then the shots are collated to form a scene.
Now if the people click on some point, the video serving algorithm will take this as one scene and therefore the user experience will be much better.
Note: To convert each scene into different formats and resolutions as we did for the chunks.
Sparse videos v/s Dense videos
If people arbitrarily go to points then Netflix assumes that it is a sparse movie. So instead of sending the entire scene it only sends the data, the user has asked for.
But if people are watching the movie for a continuous period then it is called a dense movie. It is easy to say that the next scene will be picked up. So instead of sending just the part user has asked for, it sends the entire next scene.
Netflix stores all these data in Amazon S3. It is cheaper than the database and is used to store static data.
ISP Synergy
First, let's discuss what normally happens when we send a request to Netflix.
- We send a request to the Netflix .com
- This request is first sent to the Internet Service Provider.
- ISPs have the mapping of addresses to IP addresses.
- Then the request is sent to Netflix servers.
- Then we get the response similarly.
If the Netflix servers are too far away from the user, it will take a lot of time to send and receive a signal. Especially if it is a video because there is a lot of data that is going to be coming in.
Netflix extended the concept of caching and applied it to ISPs. For example, whenever there is a request from India and it is a local movie, then instead of hitting the Netflix USA servers, requests are first sent to a device called Open Connect. Open connect can be considered as a hard drive. If the movie is found here then it sends the response back to the user.
Advantages of using this method are:
- It saves a lot of bandwidth.
- It saves a lot of time which** improves user experience.**
- Open Connect Box is localized. It can store data as per the watch history of that location.
- It reduces loads not only on the Netflix servers but also on the ISPs.
Around 90% of the requests are taken care of by Open Connect Boxes
Netflix updates the content in these Open Connect Boxes when the load on the boxes is minimum (E.g., 4 AM at the night). So it can do a lot of writing operations. New videos are processed and stored according to the method mentioned above.
