SysDesignPrep.com
Interactive concepts

Adaptive bitrate streaming: an interactive video player simulator

Adaptive bitrate streaming (ABR) is how Netflix, YouTube and every HLS or DASH player keep video playing on connections that change. The video is cut into segments of a few seconds, each encoded at a ladder of bitrates, and the player picks a bitrate for every segment it downloads. Pick too high and the buffer runs dry and the video stalls; pick too low and it looks worse than it needs to.

The playground streams a two-minute video over three kinds of connection with four players. Pick a connection, compare the players in the table, and click one to see its bitrate and buffer second by second.

Connection

A 2-minute video in 4-second segments, each available from 240p at 0.4 Mbps to 1080p at 6 Mbps, over a steady 5 Mbps. Always fetching 1080p stalls 29 times for 23.2 s in all; always 360p never stalls but looks poor the whole way. The throughput-based player averages 2.9 Mbps, mostly 720p, with 1 switch and no stalls; the buffer-based one averages 4.2 Mbps with 17 switches and no stalls.

PlayerAverageStallsSwitchesStart
Throughput-based: what it played, second by second
0369Mbps0s15s30sseconds of video buffered0 s40 s80 s120 s160 s360p480p720p1080p
bandwidthbitrate on screenbufferstalledClick a row to chart that player.

Why players adapt

On a steady 5 Mbps connection, always fetching 1080p at 6 Mbps stalls 29 times, 23 seconds in all, because each segment takes longer to download than to play. On mobile data swinging between 1 and 8 Mbps it stalls for 55 seconds and is still not done when the adaptive players have finished. Always fetching 360p never stalls, and never looks good. Adaptive players sit between: no stalls in either case, at 2.7 to 4.2 Mbps on average.

Throughput-based and buffer-based players

  • Throughput-based players measure how fast recent segments downloaded and pick the highest bitrate under a safety margin of that, here 80% of the harmonic mean of the last three. They react quickly: through a tunnel where bandwidth falls to 0.8 Mbps the player drops to 240p and recovers without a stall. But estimates are noisy and conservative, so on a steady 5 Mbps line it settles at 720p.
  • Buffer-based players ignore the estimate and choose by how much video is buffered: the lowest rung when the buffer is nearly empty, the highest when it is full. They get more quality out of the same connection, 4.2 Mbps on average on the steady line, but switch often, 17 times there, which viewers notice. And a high-bitrate segment requested just before a drop can take 30 seconds to arrive: real players abandon such downloads.
  • Hybrid players, used in production, start with throughput to pick quickly while the buffer is empty, then lean on the buffer, and damp switches with hysteresis.

Startup is its own trade-off: starting at a low rung gets the first frame on screen in well under a second, and the quality climbs as the buffer fills.

An HLS ladder

# master.m3u8: one entry per rung of the ladder
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1500000,RESOLUTION=854x480
480p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=3000000,RESOLUTION=1280x720
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=6000000,RESOLUTION=1920x1080
1080p/index.m3u8

# 720p/index.m3u8: the same 4-second segments at one bitrate
#EXTM3U
#EXT-X-TARGETDURATION:4
#EXTINF:4.0,
seg00001.ts
#EXTINF:4.0,
seg00002.ts

The server side is simple by design: every segment of every rung is a static file, so a CDN can cache them all and the player does all the adapting. Encoders pick the ladder per title, since a cartoon needs far fewer bits than a football match at the same resolution.

In a system design interview

For a video platform, describe the pipeline and the player: “Uploads are transcoded into a ladder from 240p to 4K in 4-second segments, packaged as HLS and DASH, and served from the CDN. The client player picks a rung per segment from its buffer level and measured throughput, starts at a low rung for a fast start, and reports rebuffering ratio, startup time and average bitrate, which we watch per CDN and per ISP.” Expect the follow-ups: segment length versus latency for live streams, and how the ladder is chosen.

Read the guide to video streaming or live streaming, see CDN caching, or watch a strong candidate design a video streaming service.

Questions people ask

What is adaptive bitrate streaming?

A way of delivering video in which each few seconds of video is encoded at several bitrates, and the player chooses which bitrate to download for every segment based on network conditions. HLS and MPEG-DASH both work this way, so playback continues smoothly as bandwidth changes.

How does a video player choose the bitrate?

Throughput-based players estimate bandwidth from how fast recent segments downloaded and pick the highest bitrate safely under it. Buffer-based players pick by how much video is buffered: low when the buffer is nearly empty, high when it is full. Production players combine both.

What causes video buffering or rebuffering?

The playback buffer running empty because segments download more slowly than they play, usually because the player chose a bitrate higher than the connection could sustain or the bandwidth dropped suddenly. Adaptive players lower the bitrate to prevent it.

What is a bitrate ladder?

The set of encodings a video is offered in, such as 240p at 0.4 Mbps up to 1080p at 6 Mbps or 4K at 15 Mbps. Platforms often tune the ladder per title, since simple content looks good at lower bitrates than complex, fast-moving content.

How long should video segments be?

Typically 2 to 6 seconds. Shorter segments let the player adapt and start faster and reduce latency for live streams, at the cost of more requests and slightly worse compression; longer segments are more efficient but adapt more slowly.

What is the difference between HLS and DASH?

Both split video into segments listed in a manifest and let the client adapt the bitrate. HLS, from Apple, uses m3u8 playlists and is required on Apple devices; MPEG-DASH is an open standard using XML manifests. With CMAF, both can share the same segment files.

What metrics measure streaming quality?

Rebuffering ratio, the share of viewing time spent stalled; startup time, until the first frame; average bitrate or resolution; and the number of bitrate switches. Platforms track them per device, network and CDN to find where quality suffers.