Video Streaming: Playback
Adaptive bitrate.
A viewer on a train has a connection that goes fast, then slow, then fast again. The video should keep playing, even if the picture gets a bit softer for a moment. That's adaptive bitrate streaming.

- A connection that changes
- Keep playing
- Adaptive bitrate
Choosing the next chunk
The player downloads one chunk at a time. Before each one, it measures the recent speed, and picks the best quality that fits, with some safety margin. Run it. When the connection drops, the player switches to a lower quality, and when it recovers, it climbs back up. The video never stops.
QUALITIES = [(240, 0.4), (480, 1.0), (720, 2.5), (1080, 5.0)] # (p, Mbps)
def pick(speed_mbps):
best = QUALITIES[0][0]
for p, needed in QUALITIES:
if needed <= speed_mbps * 0.8: # keep a safety margin
best = p
return best
for chunk, speed in enumerate([8, 6, 1.5, 0.7, 3.5, 9], 1):
print(f"chunk {chunk}: speed {speed} Mbps -> {pick(speed)}p")chunk 1: speed 8 Mbps -> 1080p chunk 2: speed 6 Mbps -> 720p chunk 3: speed 1.5 Mbps -> 480p chunk 4: speed 0.7 Mbps -> 240p chunk 5: speed 3.5 Mbps -> 720p chunk 6: speed 9 Mbps -> 1080p
Serving at scale
Almost all video traffic is served by CDNs, from servers close to viewers, often inside internet providers' own networks. The player fetches a small playlist file, listing all the chunks and qualities. Popular videos stay cached at the edge. And rarely watched videos are fetched from the origin only when needed.
| key | value |
|---|---|
| CDN | serves almost everything |
| Playlist | lists chunks + qualities |
| Popular videos | cached at the edge |
| Long tail | from origin on demand |
Summary
Adaptive bitrate picks each chunk's quality from the current speed, so playback never stops, and CDNs serve it all. Next, a web crawler.
Key takeaways- Measure speed
- Pick quality per chunk
- CDN delivers