under load
1. How much video will need to be processed per live stream?
Let us assume 8k footage being captured in the event. We can assume that the highest resolution devices consuming it will be 4K devices (2160p). But we can restrict ourselves to serve upto HD for live streams. Let us assume that the resolutions we want to serve are 1080p, 720p, 480p and 360p. Let us also assume that the encoding of these videos is h.264. A cricket match lasts for approximately 10 hours. A 2 hour HD movie is about 2 GB in size. We assume that a cricket match will be about 10 GB in size. => 720p footage will be about 10 / 2 = 5 GB. => 480p footage will be about 10 / 4 = 2.5 GB. => 360p footage will be about 10 / 8 = 1.25 GB. That's roughly 18.75 GB considering all resolutions. The raw video will be broken into segments, and each segment will be processed into multiple resolutions and codecs. Let us assume we have 4 codecs. That's roughly 18.75 * 4 = 75 GB.
2. How much data will be transferred from a CDN to users in a single live stream?
Assume the number of users watching a match = 10 million. Assume 50% having HD devices, and 50% having mobile 480p devices. Assume that a user watches 50% of a live stream on average. For a 10 hour match, that's 10 GB in HD. It's 10 / 4 = 2.5 GB in 480p. Total data transfer = SUM(size_of_video_type * number_of_users_for_type) * average_watch_percentage = (10 GB * 50/100 * 10^6 + 2.5 GB * 50/100 * 10^6) * 50/100 = 3.125 * 10^6 GB = 3.125 PB
POST /api/videos/uploadstream_key: Unique identifier for the stream.video_data: Raw video data sent over RTMP.metadata: Additional metadata like title, description, and tags.200 OK with a success message.400 Bad Request for validation errors.POST /api/videos/transformvideo_id: Identifier for the video to transform.target_formats: Array of desired formats (e.g., [1080p, 720p, 480p]).200 OK with transformation status details.404 Not Found if the video is not available.GET /api/videos/streamvideo_id: Identifier of the video requested.resolution: Desired resolution based on user’s device (optional).200 OK with the video stream URL.503 Service Unavailable if the stream is temporarily inaccessible.POST /api/users/preferencesuser_id: User identifier.preferences: JSON object containing user preferences like age, content restrictions.200 OK with updated preferences.400 Bad Request for validation errors.POST /api/interactions/messageuser_id: ID of the engaging user.interaction_type: Type of interaction (e.g., message, poll).content: Content of the interaction.200 OK confirming receipt.401 Unauthorized for unauthenticated requests.Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
From Live stream source via RTMP, it is received or ingested by Media ingest server performing initial processing, possibly buffering/transcoding minor segments before forwarding it. Media Ingest Server also uploads video to Distributed File System for future use.
Stream is picked up by Video Transformation service to convert into multiple resolutions or formats as required using advanced codecs.
This is then pushed to message queues where it is processed at its own pace and distributes the processed video to different CDN networks based on user location.
Video Transformation service will use ffmpeg to transform incoming videos to different resolutions and codec.
Client-side Buffer Management
Server-side Buffer Management
Content Delivery Network (CDN) with Edge Caching
The original video will be broken into chunks of equal size, and assigned to different worker nodes in the system. As these chunks are processed into different resolutions and codecs, we push the results to a distributed file system like S3. We are mainly interested in the hot chunks of the video (last 60 seconds) as most of our viewers want to view the video live.
In this we decided to offload last mile delivery to existing CDN solutions. If we choose to build our own CDN solution, the advantages are: a. Customised as per requirements b. May be cheaper in the long run c. Higher control over it's execution, future extensions and internals The disadvantages are: a. High initial cost b. May be expensive as compared to available solutions c. Is not as well tested as existing solutions d. Existing solutions may improve and get better by the time our custom solution is launched
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?