Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/System Design

How does video streaming work? (Why movies play on slow Wi-Fi)

Video is not one big file. It is tiny chunks, a menu of qualities, and a player that picks each piece. Here is how.

Derpx069 Oct · 4 min read
Contents
What's wrong with one big file?What if we cut it into chunks?How does the phone know what to download?What if there are several qualities?Who picks the quality?What if the server is too far away?So, the whole thing in one tableYour turnSources
0% read · 4 min leftBack to top ↑
On this page0%
Contents
What's wrong with one big file?What if we cut it into chunks?How does the phone know what to download?What if there are several qualities?Who picks the quality?What if the server is too far away?So, the whole thing in one tableYour turnSources

Your internet slows down for a moment. A 2-hour movie keeps playing anyway. But a small PDF from the same connection fails twice.

Weird, right? Here's the reason: streaming is just downloading many small files, and picking the quality of each one as you go. Let's build it from the simplest version up.

What's wrong with one big file?

Simplest idea: put movie.mp4 on a server and let people download it. It can play while it loads. But:

  • The connection gets slow, and the file can't get smaller. It just stalls.
  • You jump to the 90th minute and wait for data you didn't want.
  • One server, one country, 10,000 people. Good luck.
movie.mp4One big file. A slow connection means a frozen screen.
→
ChunksMany small pieces. A slow connection means a blurrier piece, not a frozen one.

So the file has to become smaller things. How small?

What if we cut it into chunks?

The server cuts the video into short pieces called segments. In Apple's HLS format (HTTP Live Streaming), the maximum segment length comes from a "target duration", and "a typical target duration is 10 seconds" (RFC 8216, section 6.2.1).

It is like mailing a long book as ten small parcels. If one gets lost, you resend one parcel, not everything.

Why this matters: a failure now costs you a few seconds, not the whole movie. But how does your phone know which pieces exist?

How does the phone know what to download?

It reads a small text file first. HLS calls it a playlist (people also say manifest). RFC 8216 states that a Media Playlist "contains a list of Media Segments, which, when played sequentially, will play the multimedia presentation."

The player downloads them in order and plays them. Plain, and that's the point. It's ordinary HTTP, the same thing websites use, and the RFC notes it's built to work with "large-scale HTTP caching infrastructure".

Now the clever part: what if one movie came in several sizes?

What if there are several qualities?

The server makes the same video in a few qualities, like 360p, 720p and 1080p. A Master Playlist "provides a set of Variant Streams, each of which describes a different version of the same content" (RFC 8216, section 2). Each version lists its bandwidth, the speed needed to play it.

Master playlist (the menu of qualities)
Low quality segments
Medium quality segments
High quality segments
Same movie, three stacks of pieces.

Who chooses a stack? Not the server. Your phone does.

Who picks the quality?

Your player. This is adaptive bitrate: it watches how fast each piece arrives. Slow? The next piece comes from a lower stack. Fast again? It climbs back up.

MDN describes the same thing: if the data rate "doesn't look like it's keeping up, we drop down to a lower bandwidth (and consequently lower quality) stream." The RFC states that clients "should switch between different Variant Streams to adapt to network conditions."

1Download piece
2Measure speed
3Pick quality for the next piece
4Repeat
The loop that runs the whole time you watch.

The player decides fresh for each piece. A blurry moment means the system is working, not breaking.

Still, all those pieces sit on one machine. Where?

What if the server is too far away?

If it's in another country, every piece travels far. A thousand viewers pressing play at once also hit that one machine together.

The fix is a CDN (content delivery network). Fastly's learning page describes it as "distributing your website's content across a global network of edge servers", so requests go to a nearby one. A nearby copy is delivered "without having to retrieve it from your origin server."

Click Next and follow what happens when you press play.

Your phone
Edge server
Origin server

The phone requests the playlist from the nearby edge server

Step 1 of 6
A CDN edge cache: the first request travels far, later ones don't.

Notice step 6: the origin wasn't touched at all. That's the whole win.

Here's the same thing as a map:

Chunking helps here too. Each segment is a normal small file with its own URL, so caches can hand popular pieces out again and again. It is like a local shop that keeps popular items in stock, so each customer doesn't need a trip to the factory.

So, the whole thing in one table

ProblemFix
One huge file freezesCut into small segments
Phone doesn't know what existsA playlist lists them
Connection speed changesSeveral qualities, pick each time
Server too far or too busyCDN edge servers keep copies

Your turn

  1. If segments were 1 second long instead of 10, what gets better and what gets worse? (Hint: count the files and playlist updates.)
  2. Your phone just switched from Wi-Fi to mobile data. Which part of the loop notices?
  3. A new web series drops tonight. Would you want the first piece cached on edge servers ahead of time? Why?
Key takeaways
  • Streaming is many small files, not one big one.
  • A playlist lists the pieces, and a master playlist lists the qualities.
  • Your player picks the quality of each next piece based on how fast the last one arrived.
  • A CDN keeps copies near you, which works nicely because each piece is a plain small file.

Sources

  • RFC 8216: HTTP Live Streaming (sections 1, 2, 4.3.3.1, 4.3.4.2, 6.2.1; I could only read up to part of section 6.2)
  • MDN: Live streaming web audio and video
  • Fastly: What is a CDN?
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
System Design · 5 minHow does a search engine find one page out of billions so fast?System Design · 5 minHow to scale a website from 1 user to 1 million usersSystem Design · 5 minWhat is Kafka? Why it keeps messages after you read them
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)