Here's a quick summary of everything we released in Q1 2024.

Architecture for a video streaming service

In this article, you'll take a closer look at the architecture of a video streaming service. You'll learn about the types of video streaming services, high-level steps involved in implementing a video streaming service, and the components involved in each step.
Rajkumar Venkatasamy

Rajkumar Venkatasamy

Jan 03, 2023
Architecture for a video streaming service

Video is one of the most popular and common types of content on the internet—Comcast reported that in 2021, 71 percent of downstream network traffic was streaming videos. The size of video files ranges from a few megabytes to several gigabytes, though, and you don't want your viewers to have to wait for videos to load before they're able to watch it. The solution to this is video streaming.

In video streaming, videos are split into multiple small chunks, which are then sent in a sequential stream to the viewer. This allows the viewer to start watching the video immediately and helps ensure that they're able to watch the video without pausing or buffering. Although this sounds simple, implementing an end-to-end video streaming service requires a number of things, such as video encoding and decoding, converting a video to multiple formats as per the target devices, storing the video files, allowing the user to find the videos available in the catalog, and allowing users to engage with the video through liking or rating it.

In this article, you'll take a closer look at the architecture of a video streaming service. You'll learn about the types of video streaming services, high-level steps involved in implementing a video streaming service, and the components involved in each step.

#What is a video streaming service?

A video streaming service is an online service through which viewers can watch video content. It often serves as an alternative to traditional cable-based entertainment service. Video streaming services can be subscription based or ad supported, or a hybrid of both. The streaming service provider has a website where subscribers or prospective subscribers can see what type of content is available and sign up for an account. Netflix, Disney+, and Amazon Prime are examples of popular video streaming service providers.

Types of video streaming services

If you have ever watched a video that's already uploaded on YouTube, you've used an on-demand video streaming service. And if you have ever watched a real-time cricket game on SonyLIV, you've used a live video streaming service. Let's take a look at these types of service in more detail.

On-demand video streaming service

In on-demand video streaming, the video is prerecorded, and can be viewed at any time the viewer chooses. The videos ready for streaming are placed in the closest proximity possible to the viewers, and may be cached in CDN servers. This approach helps to ensure a smooth, uninterrupted user experience to the subscribers while watching the videos. The video is sent over the network in chunks and ends up on users' devices, which can be mobile devices, laptops, desktops, or even smartwatches. YouTube, Netflix, Vimeo, Hulu, and Amazon Prime Video are some of the popular services in the on-demand video streaming space.

Live video streaming service

Live video streaming has similar video processing requirements as on-demand video streaming, in that the video is split into chunks, encoded and decoded, and converted into multiple formats and resolutions.

However, in the case of live video streaming, the video content is recorded, processed, and distributed in real time, with as little delay as possible. Due to the nature of live video streaming services, content can't be cached. ESPN+, YouTube Live, SonyLIV, and Twitch are some of the popular service providers in the live video streaming service space.

#Benefits of a video streaming service

Streaming video services offer a number of benefits to catalog owners.

Variety of content

Offering a variety of content allows you to reach a broad audience. By sorting the videos into galleries organized by category, you allow subscribers to easily search and access the videos. This allows subscribers from all around the world to find videos according to their preferences.

Connecting with your audience

Physical events are typically constrained by the location. Not only do people need to be in the same geographic area, but there's also a limited amount of space available for viewers at the venue. However, if the event is streamed in real-time, you can invite as many attendees as you like.

Many people are interested in attending events, but are unable to do so due to travel costs, health concerns, or work and family obligations. These people, who you would otherwise be unable to reach, can view your content online. Livestreaming allows you to stream the events to anyone around the globe without being constrained by distance or physical space.

#What are the basic requirements of a video streaming service?

A video streaming service needs a number of functionalities.

Uploading videos

Administrators or privileged content uploaders of the video streaming platform should be able to upload videos for streaming. The platform should facilitate these uploads through an intuitive UI or SDK and should support uploads in a range of formats.

Video metadata

The video streaming platform should have the capability to accept and store metadata information for a video. This includes not just the video's title and description, but also the genre, details about the cast and crew, audio language options, subtitle language options, and so on. This information will be useful for providing additional information to subscribers, and allowing users to search for videos that fit specific criteria.

Homepage and recommendation engine

A subscriber's homepage should feature a combination of content that's broadly appealing to many subscribers, such as new releases, and content tailored to the interests of that subscriber. The recommendation algorithm should use the subscriber's history to decide what content to display on their homepage.

The homepage should also allow for easy navigation to other parts of the app.

Liking and commenting

Many platforms allow users to like, rate, comment, or otherwise interact with a video. This offers the platform owners a way to gather statistics and develop a better understanding of subscribers' interests and tastes. This information can also be used to inform content recommendations.

In some cases, the information gathered can be fed back to the content production houses to provide insight into how subscribers feel about the content. The production houses can take further actions based on such insights.

Searching

The ability to find a video at ease is one of the most critical requirements of a video streaming platform. You should offer users the ability to search by metadata information like movie title, genre, language, and subtitle language to attract audiences speaking other languages. The response time of a search operation should be fast to enhance the user experience of the platform.

#Technology stack for a video streaming service

As with any software application, your technology stack serves as the foundation on which you can build a robust, scalable, performant, and highly available video streaming platform. Although it's invisible to subscribers, your technology stack plays a crucial role in creating your subscribers' video streaming service experience. In this section, you'll look at a possible technology stack for a video streaming service. This is just one of the approaches/ways to address the requirements of a video streaming service platform.

Given below is the architecture diagram for a typical video streaming service platform:

Architecture of a video streaming service

Note that some components, such as Kafka and Hygraph, are shown multiple times to show the flow between the components more clearly.

Many of these components are microservices, indicated in blue on the architecture diagram, and can be developed in any programming language of your/your team's choice. For example, you can develop the search service in Java, and the recommendation service in Python.

Uploading the video for streaming

A video streaming service needs to allow for videos and their metadata, such as video title, genre, and IMDB rating, to be uploaded to the platform. This can be accomplished through a user interface (UI) or an SDK created for this purpose.

A UI can be developed in any frontend framework, as per your team's strengths. In the case of SDK, you can use any programming language, such as Java, Scala, Go, or Python. When the uploader uploads the video and posts the upload request, the request will land on a load balancer or an API gateway.

Load balancer/API gateway

This is where all the required cross-cutting checks and operations, such as security checks, request logging, and routing the request to the target service, will be performed. Once these have been passed, the request will be routed to the corresponding microservice based on the routing rules defined in the load balancer or gateway.

Video uploading service

This is a microservice that accepts the video and uploads it to a scalable and distributed storage. Amazon Simple Storage Service, or Amazon S3, is an example of distributed storage that can be used for videos, and provides policies you can configure to protect files from access by unauthorized users and applications. Upon receiving the video, this microservice registers an event in Kafka. In this architecture, Kafka acts as a queueing system and messaging component to store the incoming events. The persisted event can also be used for auditing and tracking purposes. Once the video gets uploaded to the S3 bucket, the event is registered in Kafka. This entire video uploading operation will take place asynchronously, so the uploader doesn't need to wait for the upload process to complete.

The video uploading microservice makes an entry into the Cassandra database to hold the video's metadata and the path to the video's storage location. This storage path information will later be used when the video is retrieved from S3 storage for further processing or consumption.

Video uploading services will also persist the metadata of the uploaded video, such as video title of the video, genre, IMDB rating, producer, director, cast, and crew information, into a metadata store, such as Hygraph.

Metadata store

Hygraph is a popular content federation platform that enables you to unify data from multiple sources, enrich or transform the content, and distribute the content to any kind of destination. Metadata is especially crucial in video streaming platforms, since it gives users full context for a video that is being streamed or viewed. Video metadata can also be used for finding/searching a video by the subscribers.

This importance is easily seen in the architecture diagram, where multiple components and services are integrated with Hygraph. For instance, once the video is successfully uploaded by the video uploading service, the metadata of the video gets persisted in Hygraph. This metadata is then used as part of the results (video list) shown on the homepage of the video streaming app. When a subscriber accesses the app, the frontend makes a call to the Hygraph endpoint to get the content from the metadata store, then displays it on the app.

Another unique advantage of using Hygraph is that it can combine results from multiple sources and serve the aggregated content through a single endpoint for the video streaming app to consume. Hygraph makes it easy for the front end to combine the data from several sources in this situation without placing a burden on them. Such external source that holds/provides data is known as remote sources. A remote field is a field inside a Hygraph model that maps specific data from a remote source to an entity's entry.

In this case, a remote source might be a statistics service, and information like the number of a user has watched a specific video gets mapped to a remote field in the Hygraph schema.

You could use Hygraph not just to manage metadata, but also to draw data into Hygraph from remote sources, reducing the number of API calls that the front end needs to make.

Notification service

The notification service is a separate microservice that handles all notification-related processes. In this example context, once the video upload operation is complete and the corresponding event has been registered in Kafka, the notify service will consume the event and send a notification to the subscriber through the pre-configured channels (email, SMS, WhatsApp, Slack, and so on).

Video processing service

The video processing service is a separate microservice that takes care of key processing tasks. This includes:

  • Splitting a single video into chunks to allow for parallel processing of each video chunk, which expedites processing.
  • Video filtering to restrict or flag the videos that may contain offensive or plagiarized contents.
  • Video encoding/video format conversion process to convert videos from one format to another for better compatibility with the target device.
  • Resolution conversion, in which a video's resolution is changed to be more efficiently streamed. For example, an Ultra HD video can be converted to HD or SD resolution, which would be more suitable for a smaller screen or a lower-bandwidth connection.
  • A video uploading task will upload the individual prepared chunks into the S3 storage. As soon as the upload is complete, the relevant path information for the chunk will be persisted in the Cassandra database, and the corresponding completion events will be sent to Kafka, which acts as a queuing system for the videos uploaded. This means that the video processor will not be overwhelmed if the S3 bucket has several videos waiting to be processed.
  • Transferring the final video files to the content delivery network (CDN) servers to provide a more seamless viewing experience to the subscribers of the streaming platform.

Streaming app

Subscribers of the video streaming service use this app to sign in, search for the videos, and view the videos. This app should be accessible and responsive on multiple devices, such as smartphones, TVs, desktops, and laptops. This app can be developed in the front-end framework or library that best suits your team's strengths.

Homepage service

The homepage service is responsible for showing the video list on the subscribers' device as part of the home screen. This is especially important for video streaming platforms that have a lot of videos, the homepage service takes care of fetching the videos that are likely to be of interest to a given subscriber.

The homepage service uses the recommendation service to retrieve videos recommended for a given subscriber, and displays the result on the screen.

Consumer for search operations and search service

These are some of the microservices that enable the subscribers to search for videos based on metadata, such as language, genre, IMDB ratings, and so on.

A Kafka consumer for search operations will consume the uploaded metadata event for the videos from the Kafka topic, transform the event stream, and load it into an Elasticsearch cluster.

The search service then consumes the indexed data from Elasticsearch and serves it to meet the subscriber's search criteria. The search interface should be fast and intuitive, and should support both keyboard and voice input.

Video asset handling service

Videos are served to subscribers by the video asset handling service. When a subscriber selects a video to play, the request is sent to this service with metadata information, such as the video ID. This unique ID will be used by the asset handling service to perform a lookup on the Apache Cassandra database and identify the related video file chunks that are available for that video. Information about the video chunks is then sent to the streaming app, which sends a request to the CDN to get the video files to play the video on the subscriber's device.

Stats service

The stats service gathers all interactions on the video streaming service platform and streams them to a Kafka topic. This information can have a number of uses. One practical use case is using this information to train or improve the recommendation service.

#Conclusion

In this article, you've gotten an overview of video streaming services, looked at the two types of video streaming services, and taken a brief tour of the components in the architecture for a video streaming service.

You were also introduced to the content federation platform Hygraph. Hygraph provides content APIs to create, enrich, unify, and deliver your content across platforms. The platform can be used as a metadata store and for consolidating data from multiple sources using the remote source and remote fields features. Check out the Hygraph website for more information.

Blog Author

Rajkumar Venkatasamy

Rajkumar Venkatasamy

Rajkumar has nearly sixteen years of experience in the software industry as a developer, data modeler, tester, project lead, product consultant, data architect, ETL specialist, and technical architect. Currently he is a principal architect at an MNC. He has hands-on experience in various technologies, tools, and libraries.

Share with others

Sign up for our newsletter!

Be the first to know about releases and industry news and insights.