Skip to the lesson
Little Builders system design, explained small

Global Video Delivery Network

Imagine a bakery that has to send fresh bread to every town in the world. A whole loaf is too big to bake and ship in one go, so the baker slices it, many bakers toast the slices at the same time, and each slice is packed in small, medium and large. Little shops in every neighborhood keep the popular slices on their shelves, so most people never wait for a truck from the main bakery. A video service works the same way. It cuts each video into short pieces, prepares every piece in several qualities, and keeps copies in shops near the viewers. Then each viewer's player picks the size that fits their internet right now, piece by piece.

Upload and chunking

Slicing the loaf before anyone bakes it

When a creator uploads a movie, the first job is to keep the original file safe in long term storage. Everything else is made from it, so if a later step goes wrong, we can always start again from the original.

Next, the video is cut into short pieces, called chunks or segments, usually a few seconds long. One giant file would keep one computer busy for hours. Many short pieces can be shared out to many computers at once, like a class splitting a big puzzle so each kid builds one corner.

The cuts must land on keyframes. A video does not store every picture in full. Most pictures only store what changed since the one before, like a flip book where most pages say, same as before, but the ball moved a bit. A keyframe is a page drawn in full. A chunk that starts on a keyframe can be played on its own, which is exactly what we need. The trade-off is size: more keyframes make cutting and jumping around easier, but each full page takes extra space, so the file grows.

Remember

Save the original first, then cut the video into short chunks that each start on a full picture.

Parallel transcoding pipeline

Many cooks, each cooking one slice

Transcoding means turning a video into a different size or format, like redrawing a big painting as a postcard. For each chunk, we put a job ticket in a queue. A large group of worker computers each grab the next ticket, transcode that chunk, save the results, and come back for another.

Because the chunks do not depend on each other, a two hour movie can be finished in minutes by spreading it over hundreds of workers. If a worker crashes or a chunk fails, only that one ticket goes back into the queue to be tried again. Nobody starts the whole movie over.

When every chunk is done, a packager labels the pieces and writes the menu files that tell players what exists. The finished files are saved in origin storage, the main warehouse that everything else copies from.

The trade-off is bookkeeping. Something has to track which tickets are finished, make sure every chunk was made with the same settings so the seams never show, and build the final menu only after the very last chunk is done.

A loaf cut into slices, each in its own toaster, all toasting at once. Point at a toaster and its slice pops up done.

Remember

One job per chunk, many workers at once, and only failed chunks are tried again.

Bitrate ladder and codecs

The same picture in big, medium and small

Viewers have very different screens and internet speeds. A big TV on fast home internet wants a sharp picture. A phone on a bumpy bus ride wants something smaller that still plays smoothly. So each chunk is made in several versions, called a bitrate ladder. Bitrate is how much data is used for each second of video. More data means a sharper picture, but it needs a faster connection.

A simple ladder might be 1080p at about 5 megabits per second, 720p at about 3, 480p at about 1.5, and 360p at under 1. Big services tune these steps for each title, because a cartoon with flat colors needs far less data than a fast football game to look good.

A codec is the recipe used to squeeze the video into fewer bytes. H.264 is the old, reliable recipe that almost every device can play. Newer recipes such as AV1 often make files around a third smaller for the same quality, which saves a lot of internet traffic. But they take much more computer time to make, and older devices cannot play them. So a popular title, watched millions of times, is worth extra encodes with the newer recipe, while a rarely watched video may only get the basic ladder.

One picture made in four sizes, stacked like nesting trays. Bigger trays hold more dots, more data. Point at a size to open it up.

Remember

Make every chunk in several sizes, and spend extra computer time on newer recipes only where many viewers will benefit.

HLS, DASH and manifests

A menu that lists every slice in every size

Before the player can order anything, it needs a menu. That menu is called a manifest. It lists the qualities that exist and, for each one, the chunks in order and where to fetch them. The player reads the menu first, then downloads chunks one after another, like eating a meal course by course.

There are two popular menu styles. HLS was created by Apple and uses playlist files ending in .m3u8. MPEG-DASH is an open standard and uses manifest files ending in .mpd. Many devices understand one, and some understand both.

In the past, services often stored every chunk twice, once for each style, which doubled the storage and made caches less useful. CMAF is a shared chunk format, so both menu styles can point to the very same chunk files, and only the small menus differ. The catch is that some older devices cannot play the shared format, so a service may still keep a few extra copies for them.

Remember

The manifest is the menu, and CMAF lets HLS and DASH menus point at the same chunks.

Adaptive bitrate streaming (ABR)

Picking the size of each next slice to match the road ahead

The clever part happens inside the viewer's player. Before fetching each chunk, it asks two questions. How fast did the last chunks arrive? And how many seconds of video do I already have saved up, waiting to be played? That waiting pile is called the buffer, like snacks stacked on your plate before you get hungry.

If chunks are arriving fast and the buffer is full, the player picks a sharper version for the next chunk. If the internet slows down, for example when a train enters a tunnel, it switches to a smaller version before the buffer runs empty. A blurry picture for a few seconds is much better than a frozen spinning wheel.

Switches happen only between chunks, which is why every version of a chunk starts at the same moment on a keyframe. The trade-off is jumpiness. Switching too eagerly makes the picture flip between sharp and blurry, so good players step down quickly but climb back carefully. Many also start at a lower quality so the video begins fast, then climb.

Video chunks wait in a player's buffer. Raise the pointer for fast internet: the newest chunks come in taller, sharper.

Remember

The player watches its speed and its buffer, and picks the size of each next chunk so the video never stops.

Multi-tier CDN caching

Corner shops, regional warehouses and one main bakery

A CDN, short for content delivery network, is a large set of computers spread around the world that keep copies of files close to viewers. The closest ones are edge servers, like the corner shop on your street. Behind them are bigger regional caches, like a warehouse that serves many shops. Behind those is an origin shield, a single guard in front of the main warehouse, and at the very top is origin storage itself.

When you press play, your player asks a nearby edge. If the edge has the chunk, that is a hit, and it hands it over right away. If not, that is a miss, and the edge asks its regional cache, which asks the shield only if it misses too. Each level keeps a copy on the way back down, so the next viewer nearby gets a hit. For popular videos, the vast majority of requests are answered at the edge.

The shield has a special job. When a brand new episode comes out, many caches may miss at the same moment. The shield collapses those identical requests into one trip to the origin and shares the answer, so the origin is not buried. For big premieres, services also copy the video to the edges ahead of time.

Edge space is limited, so rarely watched videos may only live in the higher tiers, and their first viewer waits a little longer. Live streams add one more twist: their menus change every few seconds as new chunks appear, so menus are cached only very briefly, while the chunks themselves never change and can be cached for a long time.

Corner shops, a warehouse, a guard wall and the main bakery. Point at a shop: if it has no copy, the ask climbs one level at a time.

Remember

Misses climb one level at a time, the shield turns many identical misses into one, and most viewers are served from the shop down the street.

Quick recap

  1. Keep the original upload safe, then cut it into short chunks that each start on a keyframe.
  2. Put one job per chunk in a queue so many workers can transcode in parallel, and retry only the chunks that failed.
  3. Make every chunk in a ladder of sizes. Newer codecs like AV1 save data but cost more to encode, so use them where many people watch.
  4. Package the chunks for HLS and DASH with a manifest menu. CMAF lets both styles share the same files.
  5. The player picks the quality of each next chunk from its measured speed and its buffer, stepping down fast and up carefully.
  6. Edge, regional, shield and origin tiers keep most traffic close to viewers, and the shield collapses identical misses into one.

Grown-up words

and what they mean in plain words

Transcoding
Turning a video into another size, quality or format.
Chunk (segment)
A short piece of video, a few seconds long, that can be played on its own.
Keyframe
A frame stored as a full picture. Most other frames only store what changed.
Bitrate
How much data is used for each second of video. More data, sharper picture.
Codec
The recipe used to squeeze video into fewer bytes, such as H.264 or AV1.
Manifest
The menu file that lists every quality, every chunk, and where to fetch them.
HLS and MPEG-DASH
The two common streaming formats. HLS uses .m3u8 playlists and DASH uses .mpd manifests.
CMAF
A shared chunk format, so HLS and DASH can use the very same video files.
ABR
Adaptive bitrate. The player switches quality chunk by chunk to match the network.
CDN and origin shield
Servers around the world that keep copies near viewers, with one shield layer that merges misses before they reach the origin.