Video streaming platform
Design upload, transcoding, CDN delivery and adaptive bitrate streaming.
By Invicly Tech, , in System Design Deep Dive. About 11 minutes to read.
In short
A video platform ingests uploads, transcodes them into many resolutions and serves small segments from CDNs. Adaptive bitrate streaming lets the player switch quality as bandwidth changes, and storage and egress dominate the cost.
Explained simply
A video platform like YouTube or Netflix has two jobs. First, accept videos that people upload and prepare them for watching. Second, send those videos to millions of viewers smoothly, on fast and slow connections alike.
Preparing a video is called transcoding. The original file is converted into several versions: small and low quality for weak mobile signals, large and sharp for fast home internet. Each version is also cut into short pieces, a few seconds long, called segments.
When you press play, the player downloads a small list file (a manifest) that says which versions exist. It then downloads segments one by one. If your connection gets slower, it switches to a lower quality for the next segment. This is adaptive bitrate streaming, and it is why video rarely stops completely.
Almost all the bytes come from a CDN (content delivery network), a set of servers placed close to viewers around the world. Storage and network traffic are the biggest costs, so many design choices are about spending less on them.
Press Play on a diagram to walk through it one step at a time.
- 1Upload
Client sends file to object storage via pre-signed URL
- 2Upload event
Queue triggers processing job
- 3Split and transcode
Parallel workers produce 240p to 4K renditions
- 4Package segments
HLS or DASH chunks plus manifest
- 5Store and publish
Object storage, metadata DB marks ready
- 6CDN delivery
Edge caches serve segments to viewers
- Player to API: GET /videos/123/play1GET /videos/123/play
- API to Player: Manifest URL (signed)2Manifest URL (signed)
- Player to CDN edge: Fetch master manifest3Fetch master manifest
- Player to CDN edge: Fetch 720p segment 14Fetch 720p segment 1
- 5Bandwidth dropped, switch downPlayer to Player: Bandwidth dropped, switch down
- Player to CDN edge: Fetch 480p segment 26Fetch 480p segment 2
- 1Player
Requests seg_0042.ts for 720p
- 2CDN edge near the viewer
Most requests end here as cache hits
- 3Regional shield cache
Collapses misses from many edges
- 4Origin object storage
Holds every segment, rarely hit
In depth
Requirements and estimates
Clarify what matters: upload size limits, how fast a new video must be watchable, which devices play it, whether live streaming is in scope (usually not in a first pass), and target start-up time, for example under 2 seconds. Playback must be highly available; upload processing can take minutes.
The explainer's numbers show storage of several petabytes per day for a huge platform. Bandwidth is the other big figure. A useful mental table of rough bitrates for H.264 video: 480p about 1 to 2 Mbps, 720p about 3 to 5 Mbps, 1080p about 5 to 8 Mbps, and 4K about 15 to 25 Mbps. Newer codecs such as VP9 and AV1 need roughly 30 to 50 percent less for similar quality, at the cost of much slower encoding. Multiply bitrate by concurrent viewers to get egress, and you quickly see why only a CDN can serve it.
- 1 Mbps for 1 hour ≈ 450 MB
- Egress = concurrent viewers * average bitrate
- Better codecs trade encode CPU for less storage and egress
The upload and transcoding pipeline
Large files should go straight to object storage (such as S3) using a pre-signed URL and multipart upload, so a lost connection only retries one part. When the upload finishes, storage emits an event that starts a workflow.
The workflow first inspects the file (duration, resolution, codec), then splits it into chunks at keyframes (frames that can be decoded on their own). Many workers transcode chunks in parallel into each rendition, which turns a two-hour encode into minutes. A packager then produces HLS or DASH segments and manifests, a thumbnail job grabs preview images, and the metadata database marks the video ready.
Model this as a DAG (a graph of steps where each step runs after the ones it depends on) with retries per step. A failed 4K chunk should retry alone, not restart the whole video.
- Video renditions
- 240p, 360p, 480p
- 720p, 1080p
- 4K for popular or premium titles
- Audio tracks
- AAC stereo
- Extra languages if provided
- Packaging
- HLS segments and .m3u8 playlists
- DASH segments and .mpd manifest
- Extras
- Thumbnails and preview sprites
- Captions (WebVTT)
How adaptive bitrate really decides
The master manifest lists every rendition with its bandwidth and resolution. Each rendition has its own playlist of segments, typically 2 to 6 seconds long. The player keeps a buffer, for example 10 to 30 seconds of video downloaded ahead.
Player algorithms combine two signals. Throughput-based logic measures how fast recent segments downloaded and picks the highest rendition that fits under that speed with a safety margin. Buffer-based logic looks at how full the buffer is: a nearly empty buffer means step down now, a full buffer means it is safe to try higher. Real players such as hls.js, Shaka Player and the native players on phones blend both.
Shorter segments let the player react faster but add more requests and slightly worse compression. Start-up often begins at a low rendition so the first frame appears quickly, then climbs.
CDN delivery and cost trade-offs
Segments are static files, which is perfect for CDN caching. Popular videos sit in edge caches near viewers; a cache miss goes to a regional shield cache and only then to origin storage. Cache hit ratios above 90 percent are normal for popular content. Very large platforms also place their own cache boxes inside internet providers' networks (Netflix Open Connect is a public example) to cut transit costs further.
Cost levers: encode the long tail of rarely watched videos in fewer renditions and only re-encode with expensive codecs like AV1 once a video gets popular. Move old, cold originals to cheaper storage classes. Use signed URLs or tokens with short expiry so others cannot hotlink your segments and run up your bill. Watch metrics like start-up time, rebuffer ratio and average bitrate to see if savings hurt viewers.
- Hot titles: all renditions, best codec, pre-warmed at the edge
- Long tail: fewer renditions, cheaper storage
- Signed URLs stop hotlinking
Learn it in 6 short steps
About 40m each. Track them with a timer in your plan.
- 1Clarify upload and playback requirements~40m
- 2Estimate storage and bandwidth~40m
- 3Design the upload and transcoding pipeline~40m
- 4Deliver through a CDN~40m
- 5Explain adaptive bitrate streaming~40m
- 6Discuss cost trade-offs~40m
Key points
- Upload directly to object storage; never stream large files through app servers.
- Transcode chunks in parallel to finish long videos quickly.
- Segments of a few seconds let the player switch bitrate smoothly.
- The CDN serves nearly all bytes; origin only handles misses.
- Encode rarely watched videos in fewer renditions to save cost.
Key terms
Tap a card to flip it. 0/5 known
Examples
Uploads: 500 hours of video per minute
1 hour of 1080p ≈ 3 GB; all renditions ≈ 6 GB
500 * 60 * 24 * 6 GB ≈ 4.3 PB/day of new storage
Playback: 5M concurrent viewers * 5 Mbps
= 25 Tbps egress, must come from CDN edges
master.m3u8 -> 1080p.m3u8, 720p.m3u8, 480p.m3u8
720p.m3u8 -> seg_0001.ts, seg_0002.ts, ... (4 s each)Storage and bandwidth estimates and an HLS manifest.
Reading an HLS master playlist
The player first fetches the master playlist. Each EXT-X-STREAM-INF line describes one rendition: its peak bandwidth in bits per second, resolution and codecs. The next line is the URL of that rendition's own playlist. The player measures its throughput, picks a line that fits, and fetches that playlist, which lists the actual segment files. If throughput falls below 2.8 Mbps, it moves to the 480p playlist for the next segment.
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1400000,RESOLUTION=854x480
480p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
1080p/index.m3u8Transcoding one rendition with ffmpeg
A worker turns an input chunk into a 720p HLS rendition. Step 1: scale to 720 pixels high, keeping the aspect ratio. Step 2: encode with H.264 at a target bitrate with a cap and buffer. Step 3: force a keyframe every 4 seconds (-g 96 at 24 fps) so segments can start cleanly. Step 4: write 4-second segments and a playlist. Production pipelines run many of these in parallel, one per rendition and chunk.
ffmpeg -i input.mp4 \
-vf scale=-2:720 \
-c:v libx264 -preset medium -b:v 3000k -maxrate 3200k -bufsize 6000k \
-g 96 -keyint_min 96 -sc_threshold 0 \
-c:a aac -b:a 128k \
-f hls -hls_time 4 -hls_playlist_type vod \
-hls_segment_filename '720p/seg_%04d.ts' 720p/index.m3u8Quick reference
- Upload with pre-signed URLs and multipart; never through app servers
- Split at keyframes and transcode chunks in parallel
- Segments of 2 to 6 seconds; keyframe at every segment start
- Egress ≈ concurrent viewers * average bitrate
- 1080p H.264 is roughly 5 to 8 Mbps; AV1 saves about 30 to 50 percent
- Player picks quality from measured throughput and buffer level
- Edge, then shield, then origin: keep origin hits rare
- Encode the long tail cheaply; spend on popular titles
Common mistakes
- Transcoding the whole file on one machine serially.
- Serving video from origin servers instead of a CDN.
- Encoding every video in every format regardless of popularity.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
How much data does one viewer use watching a 2-hour movie at 5 Mbps?
- Exercise 2medium
Design the states a video moves through from upload to playable, and say what happens if one transcode chunk fails.
- Exercise 3hard
A live sports final expects 10 million concurrent viewers at 4 Mbps. Estimate egress and list three things you would do before the event.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is the difference between HLS and DASH?
- Both serve video as segments plus a manifest. HLS was created by Apple and uses .m3u8 playlists; DASH is an international standard using .mpd manifests. Many services package both, or use CMAF segments that work with either.
- What is a codec?
- A codec is the method used to compress and decompress video, such as H.264, HEVC, VP9 or AV1. Newer codecs make smaller files at the same quality but take more computing power to encode.
- Why does video start blurry and then get sharp?
- The player often starts at a low rendition so playback begins quickly, then moves up once it has measured your bandwidth and filled its buffer.