Design OTT Platform

Shivam Sinha
4 min readMay 19, 2023

--

OTT describes the platform that delivers streaming content via the internet across devices including mobile phones, smart TVs, computers, and tablets. The content that is streamed can include video, music, and messaging. Example: HotStar, Netflix, AmazonPrime

Functional Requirements:

  1. Upload Video
  2. Watch Video
  3. Analytics and Logs

Non Functional Requirements:

  1. Highly Available
  2. Low Latencies
  3. Global Service
  4. Read Heavy System
  5. Eventual Consistency (Why?)

Scale Estimations:

We are scaling for 200 Million users across globe.

Data

  1. Video
  2. User
    a. Video Watched
    b. Video liked
    c. Video rate
    d. Video paused at.

Video Data Estimations:

OTT platforms, unlike content creation platform(like Youtube, TikTok) has limited amount of videos.

Say, we have onboarded 1M videos/shows on our OTT platform, and on average the length of each video is 2 hours.

Based on different devices, internet speed we may need to store different resolutions and stream relevant resolution video to the users. Check ABS.

For simplicity we have 2 resolution -> SD, HD

Size: for SD -> 10GB/hour and for HD -> 20GB/hour

Total size of single video of 2 hour: (10+20)*2 = 60GB/video

Total Video Size: 60*1M = 60*10⁶ = 60 PetaByte or 60 PB.

User Data Estimations:

Say, on an average a single user watches, 2 shows/week i.e, ~100 shows/year.

Average lifetime of a user on an OTT platform: 10 years.

Logs: 100 bytes/show.

Total Size: 200*10⁶(users)*100(logs size/show)*10(years)*100(shows/year) = 20 Tera Byte or 20 TB.

We can use any Key-Value Store(KVS) like DynamoDB to store such data.

We can shard based on user_id , all data of a single user will present in a single device.

How are we going to Onboard a Video:

This section deals with video storage and optimal way to stream those videos.

We can use S3, GCS to store our videos.

  1. Store full video in SD and HD format.
    Issue: When someone is watching any show, they have to wait until full video is available to them. Consumes lot of bandwidth.
  2. (Recommended) Store videos in chunks.
    a. Say, we store a show in the chunks of 2min.
    b. For a 2 hour show there will be 60 chunks.
    c. We have 2 resolutions (SD and HD). So, total chunk count will be 120 chunks.

Video MetaData Size Estimation:


+----------+----------+------------+-----------+-----------+-----------+------------+----------+
| video_id | chunk_id | resolution | thumbnail | chunk_url | video_url | start_time | end_time |
+----------+----------+------------+-----------+-----------+-----------+------------+----------+
| 1 | 1_1 | 0 | cdn_url | cdn_url | cdn_url | 00:00:00 | 00:01:59 |
| 1 | 1_1 | 0 | cdn_url | cdn_url | cdn_url | 00:00:00 | 00:01:59 |
| 1 | 1_2 | 1 | cdn_url | cdn_url | cdn_url | 00:02:00 | 00:03:59 |
| 1 | 1_2 | 1 | cdn_url | cdn_url | cdn_url | 00:02:00 | 00:03:59 |
+----------+----------+------------+-----------+-----------+-----------+------------+----------+

Size of 1 row: ~350 bytes.

1 video: 60 chunks * 2 resolution * 350 bytes = ~40KB.

Total Size: 40 * 10⁶ KB = 40 GB. (Can be easily store in single device, RDBMS is a good choice).

How To Stream Videos:

Now, as we already discussed user logs, video onboarding let’s see how user can stream videos.

Example: Watch Avengers Infinity Wars

  1. User request for video or say fetch latest/next chunk.
  2. Request to server: /fetch_next_chunk(current_chunk_id) . In case of first chunk set current_chunk_id = -1 .
  3. After completing half (1 min) of the chunk request for next chunk.
Chunk Fetcher
  • If chunk request fail buffer on UI.

Now, let’s say OTT platform announces a new movie and everyone is waiting for this movie (like: Avengers EndGame, Avatar2) or at peak traffic 10M are online and are watching this video. This will put a lot of load on S3 storage as API Server will be requesting for video from S3.

Solution: CDN

  1. Present at different regions.
  2. It acts like a cache that stores hot/popular shows for out OTT platform at regional level.

How to populate CDN?

  1. For hot/popular video we can use a service like CachePopulatorService . Acts as a CRON and populate videos to CDN.
  2. Also for any other videos, will populate CDN only if we received say 5–10 requests for a particular videos.

Jamboard Link:

Services:

  1. User App/ Web App: Used to upload and watch/stream videos.
  2. User Activity Service: To store logs.
  3. FetchChunkService: To fetch latest/new chunk requested by user while watching videos.
  4. Upload Service: To onboard a new Show/Video.
  5. Chunk Service: To divide a video into chunks of 2 minutes.
  6. Encoder Service: Encode videos into different resolutions and formats.
  7. Recommender Service: Not covered, but we can use user_metadata and video_meatadata to build Recommender service.

High-Level Architecture:

ThankYou. Please do give suggestions.

--

--