Case study: Video streaming platform

Topic 10 of 15 in Week 7: Classic case studies15 min readAdvancedFree course

Overview

A video platform has two very different halves: a write path that ingests huge files and processes them once, and a read path that streams them billions of times. The read path is dominated by bandwidth, so the design is shaped by content delivery networks and adaptive streaming.

Try the exercise first: 45 minutes, then compare.

1. Requirements

Functional

  • Creators upload videos (up to 10 GB) with title, description and thumbnail.
  • Viewers watch on any device, with quality adapting to their network.
  • Video pages show metadata and view counts; videos are searchable.

Non-functional

  • Smooth playback: fast start (under ~2 s), few rebuffering events.
  • Uploads are reliable and resumable on poor connections.
  • Processing completes within minutes for typical videos.
  • Massive scale and cost efficiency (bandwidth and storage dominate).

2. Estimates

Text
uploads   : 500 hours / minute; raw ~1 GB / hour → ~0.5 TB / minute ≈ 720 TB / day (raw)
renditions: 5–6 resolutions × 2 codecs add roughly the same again (compressed outputs)
views     : 1B / day; average 5 minutes at ~3 Mbit/s ≈ 110 MB per view
egress    : 1B × 110 MB ≈ 110 PB / day ≈ 10 Tbit/s average

Ten terabits per second can only be served by large CDNs (often with caches inside internet providers’ networks).

3. API

Text
POST /v1/videos                → {video_id, upload_urls (multipart, presigned)}
POST /v1/videos/{id}/complete  → starts processing
GET  /v1/videos/{id}           → metadata, status, manifest URL
GET  <CDN>/videos/{id}/master.m3u8 → manifest listing renditions and segments

4. Data model

Text
videos: video_id | owner_id | title | description | status (uploading, processing, ready, failed)
        duration | renditions | manifest_url | created_at
object storage: raw/{video_id}, segments/{video_id}/{rendition}/{n}.ts|.m4s, thumbnails/…
view counts: separate counter service (approximate live, exact daily)

5. High-level design

Video platform design. A creator uploads the original file to raw object storage. A message on a job queue starts transcoders, which split and encode the video and write HLS or DASH segments to storage, updating status and metadata in a video database. Segments are served through CDN edge caches to the viewer. Each resolution, from 240p to 1080p and 4K, is cut into 2 to 6 second segments plus a manifest. With adaptive bitrate, the player picks the segment quality to match its bandwidth every few seconds. Popular videos are served almost entirely from the CDN, and long-tail videos fall back to storage.

6. Deep dives

Uploads

Large files over mobile networks fail often. Use resumable multipart uploads straight to object storage via presigned URLs: the file is split into parts (say 10 MB), each uploaded and retried independently, then combined. The API server only issues URLs and records metadata.

The transcoding pipeline

Raw uploads come in countless formats. Processing is a workflow (DAG):

  1. Validate and inspect (format, duration, codec), scan for policy violations.
  2. Split the video into chunks (for example at keyframes every few seconds).
  3. Encode each chunk into every rendition in parallel: resolutions from 240p to 4K and codecs such as H.264 (compatibility), VP9 and AV1 (better compression).
  4. Generate thumbnails and preview sprites; extract audio tracks and captions.
  5. Package into HLS and/or DASH: short segments plus manifest files.
  6. Mark the video ready; publish an event for search indexing and notifications.

Parallel chunk encoding turns hours of encoding into minutes. Workers are stateless and autoscale on queue depth; failed chunks are retried. Popular videos can be re-encoded later with more expensive codecs, since the bandwidth savings pay off.

Adaptive bitrate streaming

The player first downloads a manifest listing the available renditions and their segment URLs. It then downloads segments of a few seconds each, measuring throughput and buffer health, and switches up or down in quality between segments. This avoids rebuffering on bad networks and gives high quality on good ones. HTTP-based segments are perfectly cacheable by CDNs.

Content delivery

  • Segments are immutable, so they get long cache lifetimes.
  • Popular videos stay hot in edge caches; long-tail videos are fetched from origin storage on demand, with an origin shield layer to avoid many edges hitting storage at once.
  • Large platforms place caches inside ISPs’ networks to cut costs and latency.
  • Pre-position (push) new videos from popular creators to edges before release.

Metadata, search and counts

Metadata lives in a sharded database with caches. Search uses an index fed by video events. View counts are computed from playback events through a stream pipeline (approximate live counter) and a batch job (exact, de-duplicated counts), as in the batch and stream lesson.

Cost

Storage and egress dominate. Levers: better codecs for popular content, deleting unused renditions of rarely watched videos or moving them to cheaper storage classes, and CDN deals.

7. Trade-offs and bottlenecks

  • More renditions and codecs improve playback but multiply processing and storage.
  • Smaller segments switch quality faster but add requests and overhead.
  • Long-tail videos get lower cache hit rates and higher start latency.

8. Follow-up questions

  • Live streaming? Ingest via RTMP/SRT/WebRTC, transcode in real time, publish segments continuously with low-latency HLS; latency of seconds instead of minutes.
  • Copyright detection? Fingerprint audio and video during processing and compare with a reference database.
  • Resume watching across devices? Store playback position per user per video, updated every few seconds.

Recap

Video platforms separate a heavy, asynchronous write path from a bandwidth-dominated read path. Uploads go directly to object storage with resumable multipart uploads; a parallel transcoding workflow produces multiple renditions packaged into HLS/DASH segments; players stream segments from CDNs and adapt quality to network conditions; metadata, search and view counting run alongside.

Exercise

Design it yourself (45 minutes)

Set a 45-minute timer and design a video platform: creators upload videos up to 10 GB; viewers watch on phones, laptops and TVs with smooth playback on poor networks; 500 hours of video are uploaded per minute; 1 billion views per day. Include search and view counts only briefly. Use the framework, then compare.

Text
1. Clarifying questions:
2. Functional requirements:
3. Non-functional requirements:
4. Estimates (upload storage, streaming bandwidth):
5. API:
6. Data model:
7. High-level design (upload + streaming):
8. Deep dives (transcoding pipeline, ABR, CDN, costs):
9. Trade-offs and bottlenecks:

Summary

  • Upload directly to object storage with resumable multipart uploads and presigned URLs.
  • Transcode asynchronously: split videos into chunks and encode many resolutions and codecs in parallel workers.
  • Package into short segments with manifests (HLS/DASH) so players can switch quality adaptively.
  • Serve video through CDNs; popular content stays at the edge, the long tail comes from origin storage.
  • Keep metadata, search and view counting separate from the heavy video path.