Frontend System Design · Lesson 48 of 86 · 6 min
Video Streaming: HLS, DASH, Adaptive Bitrate
This is how you explain why a simple <video> tag isn't enough for a service like YouTube or Netflix.
When you're asked to design a video platform, your first instinct might be to point a <video> tag at a .mp4 file. That's called progressive download. It works for short clips, but it fails under real-world network conditions. The modern solution is adaptive bitrate streaming. After this lesson, you'll be able to explain exactly how it works, name the key protocols, and describe the frontend's role.
How Adaptive Bitrate Streaming (ABS) Works
Instead of one giant video file, ABS breaks the video into two things: small chunks of video and a playlist that describes them.
- Multiple Renditions: The original video is encoded into several versions at different quality levels (e.g., 360p, 720p, 1080p). Each version has a different bitrate, which is the amount of data used to represent one second of video.
- Segmentation: Each rendition is then chopped into small, independent segments, typically 2 to 6 seconds long. These are just static files (like
.tsor.fmp4). - Manifest File: A manifest file acts as a table of contents. It lists all available renditions and provides the URLs for every segment in order.
- Client Logic: The video player on the frontend is the smart part. It downloads the manifest first. Then it starts by requesting low-quality segments to get the video playing quickly. It continuously monitors network bandwidth and how much video is buffered. If the connection is fast, it switches to requesting higher-quality segments. If the connection slows down, it switches back down.
This all happens over standard HTTP. The segments are just files, which makes them perfectly cacheable by CDNs. This is critical for scaling video delivery globally.
The trap: Don't forget the trade-off in segment duration. Shorter segments (e.g., 2s) allow the player to adapt to network changes faster. But this also means more HTTP requests and a larger manifest file, which adds overhead. Longer segments (e.g., 10s) are more efficient but make the player less responsive to bandwidth fluctuations. Most services settle on 2-6 seconds.
HLS vs. DASH: The Two Dominant Protocols
HLS and DASH are the two standards that define the format of the manifest file and the video segments. They achieve the same goal but have different origins and syntax.
HLS (HTTP Live Streaming)
Developed by Apple. It's the de facto standard for the Apple ecosystem (iOS, Safari, Apple TV) and is widely supported everywhere else via JavaScript libraries.
- Manifest: Uses a text-based
.m3u8playlist. It has a master playlist listing the available quality streams, and each stream has its own media playlist listing its segments. - Segments: Traditionally used MPEG-2 Transport Stream (
.ts) containers. Modern HLS also supports Fragmented MP4 (.fmp4), which is more efficient.
DASH (Dynamic Adaptive Streaming over HTTP)
An open international standard. It's codec-agnostic and more flexible than HLS, making it popular with services like Netflix and YouTube.
- Manifest: Uses an XML-based Media Presentation Description (
.mpd) file. This format is more complex but also more powerful, allowing for more detailed descriptions of audio tracks, subtitles, and content protection. - Segments: Primarily uses Fragmented MP4 (
.fmp4).
Here is the direct comparison you should know.
| Feature | HLS | DASH |
| :--- | :--- | :--- |
| Origin | Apple | ISO (Open Standard) |
| Manifest | .m3u8 (text playlist) | .mpd (XML) |
| Segment Format| .ts, .fmp4 (newer) | .fmp4, WebM |
| Browser Support| Native on Safari/iOS. Others need hls.js. | Some native support, but dash.js is standard. |
In an interview, the correct answer to "Which one would you choose?" is almost always "Both." The media processing pipeline on the backend would generate both HLS and DASH manifests and segments to ensure compatibility across all devices. The frontend player then detects the environment and requests the appropriate manifest.
The Frontend Player's Role
A standard <video> element can't handle adaptive streaming on its own, except for Safari's native HLS support. For all other browsers, you need a JavaScript library that uses the Media Source Extensions (MSE) API.
MSE allows JavaScript to dynamically generate media streams for a <video> or <audio> element. Libraries like hls.js and dash.js use MSE under the hood. They fetch the manifest, run the adaptive bitrate logic, download the .ts or .fmp4 segments via fetch, and feed the binary data directly to the video element's buffer.
You are not implementing the ABR logic yourself. You are configuring a library that has a battle-tested implementation. Your job is to integrate it correctly.
Here is what that looks like with hls.js. This is all you'd need to show on a whiteboard.
import Hls from 'hls.js';
const video = document.getElementById('videoPlayer');
const hlsUrl = 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8';
if (Hls.isSupported()) {
const hls = new Hls();
hls.loadSource(hlsUrl);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
video.play();
});
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
// Fallback to native HLS support in Safari
video.src = hlsUrl;
}
This code checks for MSE support. If available, it uses hls.js to manage the stream. If not, it checks for native HLS support (the canPlayType check) and lets the browser handle it directly.
How to Explain Video Streaming in an Interview
Structure your answer clearly to show you understand the whole pipeline from a frontend perspective.
"For a video platform, we can't just use a standard
<video src="movie.mp4">. That's progressive download, and it will buffer constantly on variable networks. The industry standard is Adaptive Bitrate Streaming.Here's the flow:
- Preparation: On the backend, the source video is encoded into multiple renditions—say, 480p, 720p, and 1080p. Each rendition is then split into small, 2-6 second chunks.
- Manifest: A manifest file is created that acts as a playlist, listing all available quality levels and the URLs for their corresponding chunks.
- Protocols: The two main protocols for this are HLS and DASH. HLS uses a
.m3u8manifest and is required for Apple devices. DASH is an open standard using an XML-based.mpdmanifest. A robust service provides both.- Playback: On the frontend, our video player won't just point to a video file. It will use a library like
hls.jsordash.js. This library first fetches the manifest. It then constantly measures network speed and buffer size to intelligently decide which quality chunk to download next, feeding them to a standard<video>element via the Media Source Extensions API. This ensures smooth playback by adapting to the user's connection."
This answer is concise, hits all the keywords (ABS, HLS, DASH, manifest, segments, MSE), and demonstrates a clear understanding of the problem and solution.
Try it
Find a public HLS stream URL (search for "public m3u8 test stream"). Paste the .m3u8 URL into your browser's address bar. Inspect the text file to see the different bitrate options (lines starting with #EXT-X-STREAM-INF) and the URL for a specific quality's playlist. Click one of those URLs to see the list of individual .ts segment files.
Next: We'll move from streaming media to fetching application data by comparing REST and GraphQL for Frontend Engineers.
Lock it in — apply this lesson under interview conditions.