Designing a Video Streaming Service
A write path (ingest and process huge files) and a read path (stream smoothly to millions) that have almost nothing in common, working together.
Advanced
| Functional | Non-functional |
|---|---|
| Upload a video | Playback must start quickly and not stall (buffer) mid-stream |
| Stream video on demand, adjusting quality to the viewer's connection | Must support a huge range of device types and network conditions |
| Browse/search available videos | Storage and bandwidth costs at this scale are enormous and must be controlled |
| Step | What happens |
|---|---|
| Upload | The raw file is written to blob storage — never a database, given the size. |
| Enqueue processing | An upload event is placed on a distributed messaging queue, decoupling upload from the (much slower) transcoding step. |
| Transcode | A task scheduler distributes transcoding jobs — producing several resolution/bitrate variants — across a worker pool, since transcoding is CPU-intensive and fully parallelizable across videos. |
| Publish | Once transcoding completes, the video's metadata (available resolutions, thumbnail, duration) is written to the catalog database and the video becomes visible for playback. |
Available variants for one video:
240p @ 400 kbps 360p @ 800 kbps 720p @ 2500 kbps 1080p @ 5000 kbps
Player logic (simplified):
measured_bandwidth = last_segment_size / download_time
next_segment_quality = highest variant whose bitrate <= measured_bandwidth
| Requirement | How it's met |
|---|---|
| Fast playback start, no stalling | Adaptive bitrate streaming adjusts quality to real-time bandwidth instead of committing to one fixed quality. |
| Wide device/network support | Transcoding produces multiple resolution/bitrate variants ahead of time, not on demand per viewer. |
| Controlled bandwidth and storage cost | CDN edge caching means the origin serves each segment once per region; asynchronous transcoding runs once per video regardless of eventual view count. |
| Upload doesn't block on processing | The upload and transcoding pipeline is fully decoupled via a queue and a task scheduler. |