What is adaptive bitrate streaming? HLS vs DASH for frontend engineers
IntermediateBrowser and web interview questionBy UIRound, updated 23 November 2026
Short answer
Adaptive bitrate (ABR) streaming encodes a video at several qualities, cuts each into short segments, and lists them in a manifest. The player downloads segments one at a time and picks the quality for the next one from measured bandwidth and how much video is buffered. HLS (manifests in .m3u8) and MPEG-DASH (manifests in .mpd) are the two main formats. In browsers, a JavaScript player feeds segments to the video element through Media Source Extensions.
Why not just one MP4
A single progressive MP4 forces one quality on everyone. On a fast connection it may look poor; on a slow one it stalls. Seeking far ahead needs HTTP range requests, and there is no way to change quality mid-play. ABR fixes this by making quality a per-segment decision.
The building blocks
- Renditions. The same content encoded at several resolution and bitrate pairs, for example 240p up to 1080p or 4K. The set of renditions is called a bitrate ladder.
- Segments. Each rendition is cut into short chunks, commonly a few seconds long, with aligned boundaries so the player can switch at any segment edge without a visible jump.
- Manifest. A text file that describes the renditions, their codecs and bandwidth, and where the segments are. The player reads it first.
Segments are ordinary files served over HTTP, so a normal CDN caches them. That is a big reason HTTP-based ABR replaced older streaming protocols.
HLS
HTTP Live Streaming came from Apple and is published as RFC 8216. The top-level multivariant playlist (formerly called the master playlist) lists one entry per rendition:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360,CODECS="avc1.4d401e,mp4a.40.2"
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720,CODECS="avc1.4d401f,mp4a.40.2"
720p/index.m3u8Each media playlist then lists that rendition's segments with #EXTINF durations. Segments were traditionally MPEG-2 transport streams; modern HLS also supports fragmented MP4. For live streams, the player reloads the media playlist to find new segments. Low-Latency HLS adds partial segments and blocking playlist reloads to cut delay.
MPEG-DASH
Dynamic Adaptive Streaming over HTTP is an international standard (ISO/IEC 23009-1). Its manifest, the MPD (Media Presentation Description), is XML with a nested structure: a Period holds AdaptationSets (video, audio, subtitles), and each holds Representations, which are the renditions. Segment URLs are usually generated from a SegmentTemplate rather than listed one by one. DASH is codec-agnostic.
HLS vs DASH
| HLS | DASH | |
|---|---|---|
| Origin | Apple, RFC 8216 | MPEG, ISO/IEC 23009-1 |
| Manifest | .m3u8 text playlists |
.mpd XML |
| Segments | MPEG-TS or fragmented MP4 | Usually fragmented MP4 |
| Native browser playback | Safari, including iPhone; elsewhere it varies, so feature-detect | Not in major browsers; needs a JavaScript player |
| DRM | FairPlay is the usual choice on Apple devices | Widevine and PlayReady are common |
In practice, many services package once with CMAF (Common Media Application Format), which uses fragmented MP4 segments that both an HLS playlist and a DASH MPD can point to. The same files then serve every device, and only the manifests differ.
How the player picks a quality
The player decides before each segment request. There are two broad families of rules:
- Throughput-based. Measure how fast recent segments downloaded, smooth the estimate (often with an exponentially weighted moving average) and pick the highest rendition that fits under it with a safety margin. It reacts fast but is noisy on mobile networks.
- Buffer-based. Look at how many seconds are buffered ahead. A deep buffer means you can afford a higher quality; a shrinking one means step down before it runs out. BOLA, used in dash.js, is a well-known buffer-based algorithm.
Real players combine both and add rules of their own: start at a low or middle rendition so the first frame appears quickly, never pick a resolution larger than the player on screen (hls.js has capLevelToPlayerSize for this), drop down if many frames are being dropped, and avoid switching back and forth every segment. Stalls hurt viewers more than a slightly softer picture, so most players lean conservative.
Media Source Extensions
Outside Safari, you cannot count on a browser playing an .m3u8 URL directly, and no major browser plays an .mpd. Media Source Extensions (MSE) let JavaScript do it instead: the player fetches the manifest and segments itself and appends the bytes to a buffer that the <video> element plays.
const mediaSource = new MediaSource();
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener("sourceopen", async () => {
const type = 'video/mp4; codecs="avc1.4d401f"';
if (!MediaSource.isTypeSupported(type)) throw new Error("codec not supported");
const buffer = mediaSource.addSourceBuffer(type);
buffer.appendBuffer(await (await fetch("/720p/init.mp4")).arrayBuffer());
// then append media segments one by one, waiting for each "updateend"
});Because the player controls every request, it can switch rendition, retry a failed segment, or trim the buffer to save memory. iPhone Safari had no MSE for a long time; Safari 17.1 added ManagedMediaSource, a variant where the browser can ask the player to free buffered data and pause fetching.
DRM sits on top of MSE through Encrypted Media Extensions (EME), which pass licence requests to a content decryption module.
The libraries
You rarely write MSE code by hand. The common choices:
- hls.js: HLS on top of MSE.
- dash.js: the DASH Industry Forum's reference player.
- Shaka Player: from Google, plays both DASH and HLS, with strong offline and DRM support.
- Video.js: a player UI whose streaming engine handles HLS and DASH.
A typical setup with hls.js prefers MSE and falls back to native HLS:
import Hls from "hls.js";
if (Hls.isSupported()) {
const hls = new Hls({ capLevelToPlayerSize: true });
hls.loadSource("/video/master.m3u8");
hls.attachMedia(video);
} else if (video.canPlayType("application/vnd.apple.mpegurl")) {
video.src = "/video/master.m3u8"; // Safari's built-in HLS player
}With native HLS, Safari makes the quality decisions and you get less control and fewer events. That trade-off is fine for many sites.
Follow-up questions interviewers ask
How long should segments be?
Shorter segments let the player react faster and lower live latency, but mean more requests and more manifest entries. Longer ones encode more efficiently. A few seconds is a common middle ground, and live low-latency setups use partial segments instead of tiny full ones.
How would you make the first frame appear quickly?
Start with a low rendition, preload the manifest and first segment when a play is likely (on hover or when a feed item comes into view), keep the initialisation segment small and serve everything from a nearby CDN. The YouTube-style design in video playback and adaptive streaming goes into start-up time.
What metrics would you track?
Start-up time, rebuffering ratio, average bitrate, number of switches, dropped frames and playback errors by type. Report them per session so you can compare the ABR rules.
How do you handle audio and subtitle tracks?
Both formats list them separately from the video renditions: alternate renditions in HLS, extra AdaptationSets in DASH. The player loads one audio and one subtitle track and lets the user change them.
Mistakes to avoid
Serving one large MP4 to every viewer and calling it streaming
Letting the player pick 4K for a thumbnail-sized player
Switching quality on every segment because of noisy estimates
Assuming every browser plays
.m3u8natively, or sniffing the browser instead of feature-detectingForgetting CORS headers on segment and manifest responses when they come from another origin, since MSE players fetch them with JavaScript
Sources
Practise it in code
Interviewers rarely stop at the definition. These questions open in an editor with tests.
- Design YouTube frontend: video playback, adaptive streaming, and feed virtualizationHard60 min
- Design live sports streaming like Hotstar for millions of viewers: the player, adaptive bitrate, ads, live scores and chat, and fallbacksHard60 min
- Design adaptive media quality for slow networks: reduced-data mode, quality tiers and user overrideHard45 min
- Design the Netflix web app: personalised rows, hover previews and the video playerHard50 min
- Design a short-video feed like Reels or TikTok: vertical swipe, autoplay, preloading, memory limits and engagement eventsHard60 min