Video Streaming system design: how it works
Cuts each upload into short chunks at several qualities, serves them from a CDN, and switches quality as the network changes.
Loading the interactive diagram…
How Video Streaming works, step by step
Cuts each upload into short chunks at several qualities, serves them from a CDN, and switches quality as the network changes.
People
- Creator's app
- Client · Hypothetical. Someone uploading a 2 GB, 20-minute video.
- Viewer's player
- Client · Hypothetical. A video player on a phone or TV, fetching a few seconds of video at a time.
Front door and CDN
- API gateway
- Gateway · Hypothetical. The way in for uploads and "play this video" requests. Video chunks don't go through it.
- CDN
- Gateway · Hypothetical. Servers in hundreds of cities that keep copies of popular chunks close to viewers.
Services
- Upload service
- Service · Hypothetical. Receives the pieces, puts the original file together in storage, and starts processing.
- Transcode jobs
- Queue · Hypothetical. One job per video, waiting for a free transcoding worker.
- Transcoding workers
- Service · Hypothetical. Re-encode the original into several qualities, each cut into chunks of a few seconds.
- Playback service
- Service · Hypothetical. Checks the viewer may watch, and hands the player the manifest's address.
Storage
- Original uploads
- Database · Hypothetical. The original file, kept so it can be re-encoded later with better settings.
- Video metadata
- Database · Hypothetical. Title, owner, status (processing or ready) and where each version lives.
- Segment storage
- Database · Hypothetical. Every chunk of every version, plus the manifests. The CDN's source.
Flow: Upload a video
The upload is answered as soon as the original is safe; processing happens after, in the background.
- Creator's app → API gateway (Upload, piece 1 of 256). The creator picks a 2 GB file. The app sends it in 8 MB pieces, retrying any piece that fails.
- API gateway → Upload service (Pieces for video v9). The gateway passes the pieces to the upload service.
- Upload service → Original uploads (Assemble original). Once every piece has arrived, the original file is put together in storage.
- Original uploads → Upload service (Stored). The original is safe.
- Upload service → Video metadata (v9: processing). The video is recorded, marked as still processing.
- Upload service → Transcode jobs (Transcode v9). A job is queued for the transcoding workers.
- Upload service → API gateway (Uploaded, processing). The creator is answered now, without waiting for processing.
- API gateway → Creator's app (Processing…). The app shows a progress message. The next flow is what happens meanwhile.
Flow: Transcode in the background
Workers turn the original into chunks at several qualities. Background work: nobody is waiting on these steps.
- Transcode jobs → Transcoding workers (Transcode v9). A worker picks up the job. Long videos are split by time range across many workers.
- Transcoding workers → Original uploads (Read original v9). It reads the original file.
- Original uploads → Transcoding workers (2 GB, 20 min). The original arrives.
- Transcoding workers → Segment storage (5 qualities × 300 chunks). It encodes 240p to 1080p, cuts each into 4-second chunks, and writes a manifest listing them.
- Transcoding workers → Video metadata (v9: ready). The video is marked ready. It can be played from now on.
Flow: Press play
The player gets the manifest's address, then fetches chunks from the CDN, choosing a quality for each one.
- Viewer's player → API gateway (Play v9). The viewer presses play.
- API gateway → Playback service (Play v9). The gateway passes the request to the playback service.
- Playback service → Video metadata (Where is v9?). It checks the video is ready and allowed in the viewer's country, and finds its manifest.
- Video metadata → Playback service (Ready, manifest m9). Ready to play.
- Playback service → API gateway (Signed manifest URL). It answers with a signed CDN address for the manifest, valid for a few hours.
- API gateway → Viewer's player (Manifest URL). The player now knows where to fetch the video. From here on, the API isn't involved.
- Viewer's player → CDN (GET manifest m9). The player downloads the manifest itself from the CDN: a short list of the available qualities and their chunks.
- CDN → Viewer's player (5 qualities, 300 chunks). Now it knows what it can ask for.
- Viewer's player → CDN (Chunk 1 @ 480p). The player starts at a medium quality so playback begins quickly.
- CDN → Viewer's player (4 s of video). That chunk downloaded in half a second: the network can handle more.
- Viewer's player → CDN (Chunk 2 @ 1080p). So it asks for the next chunk at 1080p. If the network slows down later, it steps back down instead of stopping to buffer.
- CDN → Viewer's player (4 s of video). Playback continues, one chunk at a time.
Flow: A chunk the CDN doesn't have yet
The first viewer in a city waits a little longer; everyone after them is served from the CDN.
- Viewer's player → CDN (Chunk 37 @ 720p). The player asks for a chunk no one nearby has watched yet.
- CDN → Segment storage (Fetch chunk 37 @ 720p). The CDN server doesn't have it, so it fetches it from segment storage.
- Segment storage → CDN (Chunk). Storage sends it. The CDN keeps a copy.
- CDN → Viewer's player (4 s of video). The viewer gets it. The next viewer in this city gets it straight from the CDN.
HowItScales is not affiliated with the companies shown. Components marked Assumption or Hypothetical are not confirmed by the company.