Design a Video Streaming Platform: Transcoding, Chunks and CDN
The upload pipeline, transcoding into multiple qualities, segmenting video into chunks, adaptive bitrate streaming and CDN delivery, explained end to end.
A video streaming platform lets users upload videos and lets a much larger audience watch them on any device and any network. When the network becomes weak, the picture quality drops but playback continues without stopping.
That behaviour is impossible if the video is one large file downloaded from one server. These notes describe the two pipelines of a streaming platform: the upload and processing path, and the playback path.
1. Requirements
- Functional: upload a video; watch a video.
- Functional: playback works on phones, laptops and TVs, at different resolutions.
- Non-functional: playback starts quickly and buffering is minimal, on fast and slow networks.
- Non-functional: high availability for playback; uploaded videos are never lost (durability).
- Workload: very read-heavy. A video is uploaded once and may be watched millions of times.
- Out of scope unless asked: recommendations, comments, live streaming.
2. Scale estimation
Assume 10 million daily active users watching 5 videos each: 50 million views per day. Assume 100,000 uploads per day with an average source size of 500 MB: 50 TB of new source video per day, and after transcoding into several qualities perhaps 100 TB per day in total. Over a year that is tens of petabytes, so storage must be object storage, not a database or local disks.
Bandwidth dominates the cost. If 500,000 users watch concurrently at an average of 3 Mbps, the platform delivers 1.5 Tbps. No origin data centre should serve that directly, which is why a CDN is essential.
3. Upload path
Video files are large, so they should not pass through the application servers. The client asks the upload service for permission, receives a pre-signed URL, and uploads the file directly to object storage. The upload is split into parts so that a failed part can be retried without restarting, and an interrupted upload can be resumed.
Information about the video (title, description, owner, duration, status, and the locations of its files) is stored separately in a metadata database. The two stores have opposite characteristics: object storage holds huge, immutable blobs cheaply; the metadata database holds small records that are queried and updated.
POST /api/v1/videos
Body: { "title": "...", "sizeBytes": 524288000 }
Response: 201 { "videoId": "v_301", "uploadUrl": "<pre-signed object storage URL>" }
# Client uploads the file in parts directly to object storage,
# then storage emits an "upload completed" event.
GET /api/v1/videos/v_301
Response: 200 { "title": "...", "status": "READY",
"manifestUrl": "https://cdn.example.com/v_301/master.m3u8" }4. Transcoding
The uploaded file is in whatever format and resolution the creator's device produced. It cannot be served as is: a 4K file is useless to a phone on a slow connection, and different devices support different codecs.
Transcoding converts the source into a set of standard outputs: several resolutions and bitrates, for example 240p, 360p, 480p, 720p, 1080p and 4K, in one or more codecs. This set is called the bitrate ladder.
Transcoding is CPU-intensive and can take longer than the video's duration. It must not block the upload request. When the upload completes, a job is placed on a queue. A pool of workers consumes the jobs. To go faster, the source is first split into segments, and many workers transcode different segments and different qualities in parallel; the results are then assembled. If a worker fails, only its segment is retried. Once all outputs exist, the video's status changes to READY.
5. Chunks and the manifest
Each quality level is cut into small chunks, typically 2 to 10 seconds long, each of which can be decoded independently. Alongside the chunks the pipeline produces a manifest file: a small text file that lists the available qualities and the URL of every chunk in each quality. The common formats are HLS and MPEG-DASH.
Chunking brings several benefits. Playback can begin after downloading the first chunk. Seeking to the middle of a video downloads only the chunks from that point. And, most importantly, the player can change quality at every chunk boundary.
#EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=400000,RESOLUTION=426x240 240p/playlist.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360 360p/playlist.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720 720p/playlist.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080 1080p/playlist.m3u8 # Each playlist lists that quality's chunks: # segment_0001.ts, segment_0002.ts, segment_0003.ts ...
6. Adaptive bitrate streaming
The player, not the server, decides the quality. It downloads the manifest and then requests chunks one after another. While doing so it measures how fast chunks are arriving and how much video is buffered. If the measured throughput is high, it requests the next chunk from a higher quality. If the network slows or the buffer is draining, it requests the next chunk from a lower quality.
This is adaptive bitrate streaming. Because chunks of every quality are aligned to the same time boundaries, switching is seamless: the viewer sees a change in sharpness but no pause. It is why a video on a train drops from 1080p to 360p in a tunnel and keeps playing.
7. CDN delivery
Serving every viewer from a central origin would overload the origin and give distant users high latency. Chunks are static files that never change once created, which makes them ideal for a content delivery network. The CDN caches chunks on edge servers in many locations. A viewer's request goes to a nearby edge. If the chunk is cached there, it is returned at once. If not, the edge fetches it from the origin, stores it and returns it.
Popular videos are served almost entirely from the edge. Rarely watched videos, the long tail, may not be cached everywhere and are fetched from the origin on demand, which is a deliberate cost trade-off.
UPLOAD AND PROCESSING
Creator --> Upload service --> pre-signed URL
| |
+------ direct upload -----> Object storage (source files)
| "upload completed" event
v
Transcoding queue --> Transcoding workers (parallel)
|
v
Object storage (chunks + manifests, per quality)
|
Metadata DB: status = READY, manifest URL
PLAYBACK
Viewer --> Video API --> Metadata DB / cache (title, manifest URL)
Player --> CDN edge --> (cache miss) --> Origin: object storage
<-- manifest, then chunks at the quality chosen by the player8. Additional considerations
- Metadata reads are also read-heavy, so video details are cached and the database uses read replicas.
- Storage cost: move rarely watched videos to cheaper storage tiers, and transcode the highest resolutions only for videos that become popular.
- Access control: signed URLs or tokens with a short lifetime prevent hotlinking; encryption and DRM protect paid content.
- View counts: recorded as events through a queue and aggregated asynchronously, never as a database write in the playback path.
- Live streaming uses the same chunk and manifest model, but chunks are produced continuously and cached for only a few seconds, so end-to-end latency is the main concern.
Interview summary
- Requirements: low buffering on any device and network, durable uploads, read-heavy.
- Storage: video files in object storage, details in a metadata database.
- Transcoding: asynchronous, through a queue with parallel workers, into a ladder of qualities.
- Chunks plus a manifest enable adaptive bitrate streaming driven by the player.
- Delivery: chunks are served from CDN edge servers, not from the origin.
Summary
A streaming platform separates processing from playback. Uploads go directly to object storage and are transcoded asynchronously into several qualities, each cut into short chunks described by a manifest. The player picks the quality of each chunk according to the network, and a CDN serves those chunks from locations close to the viewer.
Puneet Tiwari
Full Stack Developer
