InterviewKata
Software architecture · Case study 05 · Cost and economics

Prime Video: from serverless to one process

In March 2023 an engineer on Amazon Prime Video's video quality analysis team described how they rebuilt a stream-monitoring service. The first version was built from serverless parts orchestrated by a workflow engine. It hit a hard scaling limit at about 5% of the load it needed, and it cost too much to run at scale. Moving every component into a single process cut infrastructure cost by over 90% and let it monitor thousands of streams. The post was widely retold as "Amazon abandons microservices"; it says something narrower and more useful.

Real caseAnalysed from "Scaling up the Prime Video audio/video monitoring service and reducing costs by 90%" (Marcin Kolny, Prime Video Tech, 22 March 2023; archived copy). Figures in the lab are illustrative, not Prime Video's.

1. The situation

Prime Video streams live events to millions of viewers, and the team wanted to detect quality defects automatically: frozen video, block corruption, audio and video out of sync. The service has three parts: a media converter that turns a stream into frames and audio buffers, defect detectors that each analyse those frames for one kind of problem, and orchestration that controls the flow for each stream.

The first version was built quickly from managed serverless parts: AWS Step Functions orchestrated each stream, the converter uploaded frames to an Amazon S3 bucket, and each detector ran as AWS Lambda functions that downloaded the frames from S3.

2. What mattered

The first version failed on the first two. The post names two causes: Step Functions performed several state transitions for every second of every stream, which reached account limits and is billed per transition; and passing frames between components through S3 meant a high number of S3 requests, which was expensive.

3. The options

OptionGoodBad
Fix each bottleneckKeeps the design; the team first considered thisOrchestration and data hand-offs are the design: every fix fights the per-operation pricing
Keep services, change the plumbingDetectors still scale independentlyFrames would still cross the network between processes on every hop
One process per stream groupFrames passed in memory; orchestration is plain code; runs on EC2/ECS, where compute savings plans applyDetectors scale only vertically, within one instance; adding a detector is a deployment of the whole service

4. The decision

The team chose the third option. Written as an ADR, it would read:

ADR: Run the monitoring pipeline as one process per instance

Status: Accepted
Context: Step Functions makes several state transitions per second of each
  stream and reached account limits at ~5% of expected load; frames passed via
  S3 cause a high, billed request volume. Components are tightly sequenced and
  exchange large data (frames) many times a second.
Decision: Run converter, detectors and orchestration in one process on ECS
  (EC2). Pass frames in memory. When detectors exceed one instance, run several
  copies of the service, each with a subset of detectors, behind a lightweight
  layer that distributes requests.
Consequences:
  + No per-transition or per-request charges on the hot path; savings plans apply
  + Simpler orchestration; same components and most of the code reused
  - Detectors scale vertically; capacity per copy is bounded by one instance
  - Media conversion is repeated in each copy, by choice (cheaper than caching it)
Revisit: if a detector needs independent scaling or a separate release cycle

5. How it works

One stream through the first design, then through the second. Box text shows where each frame goes and what is billed.

6. The numbers

The post gives the result (over 90% lower infrastructure cost) but not the inputs. This lab rebuilds the shape with AWS list prices and invented workload figures: per frame, the first design pays one S3 upload, one download per detector, a Lambda run per detector and several workflow transitions; the second pays for instance time.

Illustrative assumptions, not Prime Video's figures: each frame makes (detectors + 2) Step Functions Standard transitions at $0.000025 each; one S3 PUT ($0.005 per 1,000) and one GET per detector ($0.0004 per 1,000); a 1 GB Lambda running 200 ms per detector per frame ($0.0000166667 per GB-second plus $0.20 per million requests). In the second design, one instance costing $0.17 an hour processes 40 detector-frames a second.

7. What happened

The post reports that the move cut infrastructure cost by over 90% and increased scaling capacity: the service handles thousands of streams with room to grow, and it can monitor every stream customers watch, not only the most viewed. Running on EC2 and ECS also let the team use compute savings plans. Because the high-level architecture stayed the same (the same converter, detectors and orchestration), much of the code was reused and the migration was quick.

Two details are easy to miss. When the detectors outgrew one instance, the team cloned the whole service, giving each copy a different subset of detectors: scaling by partitioning the work, not by splitting the process. And they chose to repeat the expensive media conversion in each copy rather than run it once and share the result, because sharing it turned out to cost more.

8. Lessons

9. Your turn

  1. Find the hot path (10 min). In a system you know, list each network hop or managed-service call that happens per request or per event. Which are billed per operation?
  2. Draw the quanta (10 min). Which components always scale together and exchange data in a fixed sequence? Would they be cheaper as one deployable unit?
  3. Write the revisit trigger (5 min). For the Prime Video ADR, what would make you split the detectors out again?
Say it in the interview
  • "Prime Video went back to a monolith. Should we?" They merged one service whose parts passed frames to each other many times a second through a workflow engine and S3, both billed per operation. Merge parts that form one quantum like that; keep separate the ones that need to scale or release independently.

10. Check yourself

According to the post, what were the two main causes of cost and scaling problems in the first design?

Orchestration made several billed transitions per second of stream and hit account limits; S3 request volume for frames was expensive.

How did the team scale once the detectors no longer fitted in one instance?

Each copy is parameterised with different detectors, behind a lightweight layer that distributes requests.

Why was the migration quick?

The logical architecture was kept, so much of the code was reused.

11. Sources and further reading

SourceWhy
Scaling up the Prime Video audio/video monitoring service and reducing costs by 90% (archived)The original post: every fact in sections 1, 2, 4 and 7.
AWS Step Functions pricingPer-transition pricing used in the lab.
Amazon S3 pricingRequest prices used in the lab.