Exploring Amazon Prime Video’s Architecture: Migrating from Microservices to Monolith for Audio/Video Monitoring Service

Anshita Bhasin
7 min readMay 14, 2023

--

Amazon Prime Video is one of the world’s largest streaming services, serving millions of customers across the globe. To provide a seamless viewing experience to its users, the company has set up a tool to monitor every stream viewed by customers which analyzes the quality of audio and video streams in real-time which was built on Microservice infrastructure but as the number of streams on the platform increased, this infra faced scaling bottlenecks and turned out to be very expensive.

In this blog post, I will discuss how Prime Video moved from distributed Microservices to a Monolith application and how it helped in scaling and reducing costs.

Before diving deep into the topic, let’s understand the basic terminologies which will be used in the blog.

Monolith:

A software architecture where all a service's components are bundled into a single codebase. This approach is simpler to develop and deploy but can become difficult to maintain and scale as the application grows.

Let’s understand with examples:

Example1: Consider a restaurant that offers dine-in, take-out, and delivery services. A Monolith architecture would be like having one kitchen and the same chef where all the food is prepared and one person managing all the orders, whether for dine-in, take-out, or delivery, go through the same kitchen. In this setup, any changes to the menu or the ordering process would affect the entire kitchen and chef.

Example2: Consider a big department store that sells everything from clothing to electronics. A Monolith architecture would be like the entire store being managed by one person who has to make decisions for all the departments.

Microservices:

A software architecture where each component of a service is developed and deployed independently. This approach allows for better fault isolation, scalability, and agility.

Let’s understand with the examples:

Example1: Take the same restaurant example,that offers dine-in, take-out, and delivery services. A Microservice architecture would be like having separate kitchens for each service (dine-in, take-out, delivery) with their own chefs and managers to handle their specific orders. This setup allows for greater flexibility and specialization in the kitchen, as well as the ability to make changes to individual services without affecting others.

Example2: Consider a big department store that sells everything from clothing to electronics. A Microservice architecture would be like each department being managed by its manager who can make decisions for their department.

Modulith:

A hybrid architecture that combines the best of both Monolith and Microservices architectures. It is a monolith architecture broken down into loosely-coupled modules, with each module being developed and deployed independently. This approach allows for better scalability and maintainability than a monolith while avoiding the complexities of Microservices.

Let’s understand with the examples:

Example1: Take the same restaurant example, that offers dine-in, take-out, and delivery services. A Modulith architecture would be like, where the restaurant has separate kitchens for dine-in and take-out/delivery, but they are still managed by one chef and share certain resources. This setup allows for some specialization and flexibility but also ensures consistency across the two main services offered by the restaurant. Additionally, any changes made to the shared resources (such as ingredients or equipment) would affect both kitchens.

Aamzon EC2:

Amazon Web Services Elastic Compute Cloud is a web service that provides scalable computing capacity in the cloud according to the user’s requirements, paying only for the resources they use. It provides a reliable, secure, and scalable infrastructure for running applications and services in the cloud. It is commonly used for hosting websites, running batch jobs, and deploying applications

Amazon ECS:

Amazon Web Services Elastic Container Service is a highly scalable container management service that makes running, stopping, and managing Docker containers on a cluster easy. ECS can be used to manage the container instances and ensure that your code is always running.

AWS Step Functions:

A web service that enables you to build applications with multiple AWS services and orchestrate them using visual workflows.

Lambda Function:

An event-driven, serverless computing service provided by AWS that allows you to run your code without having to worry about the underlying infrastructure. With AWS Lambda, you can create and run functions that respond to events triggered by other AWS services, such as S3, DynamoDB, or API Gateway.

S3 Bucket:

Amazon Simple Storage Service is a highly scalable object storage service that is used to store and retrieve files and objects.

Why Amazon Prime Video decided to migrate the Audio-Video Monitoring Service to a Monolithic architecture.

The Prime Video service was initially set up using Serverless Components such as AWS Step Functions and Lambda Functions, which allowed for a quick and easy building process.

However, as the service began to scale due to high traffic, it was discovered that there were numerous state transactions occurring every second of the stream. These transactions included a high volume of read and write operations to S3 buckets, as well as communication between AWS Lambda and S3 Buckets. As a result, the cost of the service became very expensive.

The main components of this service were

Media Converters, which were responsible to splits audio and video videos into frames and uploading them to the Amazon S3 bucket and call detectors.

Detectors which were responsible for monitoring the defects in the frames such as audio/video synchronization issues, and video freeze issues. The detectors processed the downloaded images in parallel using AWS Lambda and uploaded the results to Amazon S3.

And the third component which provided orchestration that governed the service flow using AWS Step Functions.

The use of Step Functions ensured that the various components of the service worked together seamlessly and efficiently, providing a smooth and uninterrupted streaming experience to the users.

However, as the traffic on the service increased, it was found that there were frequent state transactions for every second of the stream, resulting in a high volume of read and write to S3 buckets along with communication between AWS Lambda and S3 Buckets, which was very expensive.

Below is the diagram of the Serverless architecture which was getting used before, in Amazon Prime Video for Audio-Video Monitoring Service.

Source: primevideotech

As shown above, the whole architecture was built using serverless architecture which was using AWS Step Functions, AWS Lambda, Media Converters, and Defect Detectors.

As per the above infrastructure diagram, each service component was developed and deployed independently. While this architecture allowed for greater flexibility and scalability, it also introduced complexity and overhead in managing and deploying the service.

So, the team decided to restructure the approach and used a single process for all the components and focus on cost and scaling bottlenecks.

Below is the diagram that shows the architecture of the system after migrating to the monolith

As shown in the above diagram, it can be seen that all the components are now kept in a single process and there is only one S3 Bucket.

The components are still the same in the new architecture as well including Media Converters, Defect Detectors, and Orchestration but now they are running within the same instance.

The new architecture allows for better resource utilization. Combining the Media Conversion service and Defect Detectors into a single instance, the system can use resources more efficiently, reducing the need for redundant resources and minimizing resource wastage.

Now, services like Defect Detectors can be scaled up or down based on the volume of audio and video content and user traffic that Amazon Prime Video experiences, especially during peak usage periods. With this approach, it leads to cost savings and better overall system performance.

It is important to note that the decision to move to a single instance architecture was specific to the Audio-Video Monitoring Service and may not be applicable to other components of Amazon Prime Video’s streaming service.

Conclusion:

The migration of the Audio-Video Monitoring Service from Microservices to Monolith was a significant change in Amazon Prime Video’s architecture. The new architecture utilizes AWS services such as ECS and Amazon EC2 for scalability and flexibility which helped in improving operational efficiency and reducing costs.

While Microservices are currently popular, Amazon Prime Video’s move back to a Monolithic architecture has sparked discussion in the industry and proves that there’s no one-size-fits-all solution in software development.

So, It is very important to carefully evaluate the trade-offs between Monolithic and Microservices architectures for each component of a system to determine the most appropriate architecture.

Thanks for reading. Happy Learning! — AB

Ref: https://www.primevideotech.com/video-streaming/scaling-up-the-prime-video-audio-video-monitoring-service-and-reducing-costs-by-90

Thanks, Naveen AutomationLabs for the constant support and guidance.

Anshita Bhasin
Sr. Automation Engineer

GitHub | LinkedIn | Twitter | Youtube | Topmate

--

--

Anshita Bhasin

QA Chapter Lead at Proptech company in Dubai.. Here to share and learn new things! Youtube => ABAutomationHub