Module 07 // Case studiesLesson 29 / 3426 min read
Design a video streaming service
A video service accepts large uploads, converts each video into many sizes and formats, and streams small segments to viewers through a CDN, adjusting quality as their connection changes.
Think of it like this
Analogy
A film distributor gets a single master reel from a studio. It makes copies in many formats: cinema, TV, phone. It cuts them into short reels so a cinema can start showing right away instead of waiting for the whole film. And it stores copies in warehouses in every city so no cinema has to wait for a delivery from the other side of the country.
The problem it solves
Video is the heaviest thing on the internet. A single 4K movie is many gigabytes; millions of people watching at once means enormous bandwidth. Viewers are on everything from fiber to a shaky train connection, and they expect playback to start in a second or two without buffering. Creators upload huge files that need processing before anyone can watch.
A real example
Example
Watching a film on a train
You start a film at the station on good Wi-Fi. The player reads the manifest, which lists the film in several qualities, each cut into 4-second segments, and starts with 1080p segments from a nearby CDN edge.
The train enters a tunnel and your speed drops. The player sees the next segment arriving slowly and switches to 480p for the following few segments. The picture gets softer but doesn't stop. It's playing from the 30 seconds it had already buffered.
Out of the tunnel, the downloads speed up again, and the player steps back up to 1080p. All of this is adaptive bitrate streaming, and the server did nothing special. The player made every decision.
How it works
1. Requirements
Functional: upload videos; process them for playback; stream on any device; resume where you left off; search and browse a catalog.
Non-functional: playback starts fast (under ~2 s) with minimal buffering; very high read bandwidth; durable storage of originals; processing within minutes of upload.
2. Estimates
5 M daily viewers watching 1 hour at an average of 3 Mbps is 5 M × 3,600 s × 3 Mbps ÷ 8 ≈ 6.75 PB a day served, almost all by the CDN. 500,000 hours of new video a month stored at several renditions adds petabytes per year. Bandwidth and storage dominate cost.
3. Upload pipeline
- The client asks the API to start an upload and gets a presigned multipart upload URL (lesson 13).
- The client uploads the original straight to object storage, resumably, in parallel parts.
- A storage event puts a job on a queue.
- Workers validate, split into chunks, transcode each chunk into a ladder of resolutions and bitrates (say 240p to 4K) and codecs, generate thumbnails, and write HLS/DASH segments plus manifest files.
- When all renditions are ready, the video's status flips to “published”.
4. Adaptive bitrate streaming
With adaptive bitrate streaming (HLS or DASH), each rendition is cut into segments of a few seconds. A manifest lists the renditions and segment URLs. The player downloads the manifest, starts at a modest quality, measures throughput, and picks the next segment's quality accordingly. When your train enters a tunnel, it drops to 360p instead of stalling.
5. Delivery
Segments are static files, ideal for a CDN (lesson 15). Popular videos stay cached at the edge; the long tail is fetched from origin storage on demand. Large services also pre-position popular titles in edge caches before peak hours.
6. The whole picture
Reference architectureVideo streaming
- Creator to Amazon S3: upload
- Amazon S3 to Amazon SQS
- Amazon SQS to AWS Elemental MediaConvert
- AWS Elemental MediaConvert to Amazon S3
- Amazon S3 to CloudFront: origin
- Viewers to ECS on Fargate
- ECS on Fargate to Aurora PostgreSQL
- Viewers to CloudFront: video
7. Other pieces
- Metadata and catalog (titles, owners, status) in a relational database; search in a search index.
- Watch progress written every few seconds to a key-value store keyed by user and video.
- View counts aggregated asynchronously from playback events.
- DRM and signed URLs protect paid content.
Trade-offs
What you gain
- CDN delivery scales to huge audiences at a manageable cost.
- Adaptive bitrate adapts to every network and device.
- An async, parallel pipeline turns big uploads into playable video quickly.
What it costs you
- Storing many renditions multiplies storage.
- Transcoding is compute-heavy and costly.
- CDN egress is a major ongoing expense.
When not to use it
- For a handful of internal videos, a hosted video platform is cheaper than building a pipeline.
- Don't generate 4K renditions for content nobody watches in 4K; tailor the ladder to the source and audience.
In the cloud
Content delivery networkEvery major cloud sells this as a managed service, so you configure it rather than build it.
AWS1
- Amazon CloudFront (opens vendor docs)
Global CDN that caches content at edge locations close to users.
Azure1
- Azure Front Door (opens vendor docs)
Microsoft's global CDN and Layer 7 entry point; replaces the retiring Azure CDN (classic).
Google Cloud2
- Cloud CDN (opens vendor docs)
Caches content from Google Cloud load balancers at Google's edge locations.
- Media CDN (opens vendor docs)
Google's CDN built for large video and download traffic.
Static files live in object storage; the CDN caches them at the edge and only asks the origin on a miss.
- Route 53
- CloudFront
- S3 bucket (origin)
Interview questions
Try answering out loud first, then open the model answer.
Walk me through what happens from upload to the first viewer pressing play.
Model answer
The creator gets a presigned multipart URL and uploads the original to object storage. An upload-complete event enqueues a processing job. Workers split the video into chunks, transcode each chunk in parallel into a bitrate ladder, package HLS/DASH segments and manifests, create thumbnails, and write everything to an output bucket; the metadata row is updated to “published”. When a viewer presses play, the app fetches metadata and a signed manifest URL; the player downloads the manifest and segments from the nearest CDN edge, which pulls them from origin storage on a miss and caches them.
How do you keep video start-up time low?
Model answer
Serve manifests and the first segments from the CDN, prefetch them when the user hovers or opens a page, start with a lower-bitrate rendition and ramp up, use short initial segments, keep the player's first request count low, and pre-warm edge caches for popular or newly released titles. Use HTTP/2 or HTTP/3 to reduce connection overhead.
How would you reduce storage and delivery cost?
Model answer
Use efficient codecs (AV1 or HEVC where devices support them), tailor the bitrate ladder per title, transcode rarely watched videos on demand rather than up front, move old originals and unpopular renditions to colder storage tiers, maximize CDN cache hit ratio with an origin shield, and negotiate committed-use pricing for CDN egress.
Quiz
Pick an answer to see whether it’s right and why.
0 of 6 answered
Key terms
- Adaptive bitrate streaming
- Video split into small segments at several qualities; the player switches quality as the network changes.
- Object storage
- Storage for whole files (objects) addressed by a key in a bucket, with nearly unlimited capacity.
- CDN
- Content delivery network. Servers around the world that keep copies of files close to users.
- Message queue
- A buffer where producers leave messages and consumers pick them up later, so neither waits for the other.
- Presigned URL
- A temporary link that lets someone upload or download one object without having your credentials.
- Bandwidth
- How much data a link can carry per second, such as 1 Gbps.
Progress is saved in this browser only.