Sub topic 15
Extending the design to live streaming
This chapter assumes you know the on-demand pipeline from earlier chapters: transcoding, a bitrate ladder, HLS segments, and CDN caching. Live streaming reuses those parts, but the input never ends and viewers expect to watch it within seconds.
What changes for live
In on-demand video, the whole file exists before anyone presses play. In live, the source is a camera feed, and each segment is created only a few seconds before it is played.
| Concern | On demand | Live |
|---|---|---|
| Source | Uploaded file | Continuous stream (RTMP or SRT) |
| Transcoding | Batch, can take longer than the video | Real time, must keep up with the feed |
| Playlist | Fixed, ends with `#EXT-X-ENDLIST` | Grows and slides, never ends |
| Playlist caching | Long TTL | Very short TTL, about one segment duration |
| Failure | Retry the job | Viewers see it immediately |
The live pipeline
The ingest server accepts a long-lived connection from the broadcaster. The transcoder produces every rung of the ladder at once, and all rungs must keep the same segment boundaries so the player can switch between them. The packager writes a new segment every few seconds and updates the playlist.
The sliding playlist
A live media playlist lists only the most recent segments. The EXT-X-MEDIA-SEQUENCE number increases as old segments drop off the top.
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:4
#EXT-X-MEDIA-SEQUENCE:2681
#EXTINF:4.000,
seg_2681.ts
#EXTINF:4.000,
seg_2682.ts
#EXTINF:4.000,
seg_2683.tsThe player reloads this file about once per segment duration to find new entries. Because there is no #EXT-X-ENDLIST tag, the player knows more segments will come. If you keep a longer window of old segments, viewers can rewind (DVR). When the event ends, you add #EXT-X-ENDLIST and the same segments become a VOD asset.
Latency
Players usually start a few segments behind the live edge, commonly three. With 4-second segments, that is about 12 seconds of delay. Encoding, packaging, and CDN propagation add a few more seconds.
You can lower latency in two ways:
- Use shorter segments, such as 2 seconds. This costs more requests, and each segment compresses slightly worse because keyframes are more frequent.
- Use low-latency HLS or CMAF chunked transfer. Segments are split into small parts that the player can fetch before the full segment is finished. This needs CDN and origin support for chunked responses.
CDN behavior under live load
Thousands of viewers request the same new segment at nearly the same moment. Without protection, every CDN edge misses the cache and hits the origin together. Two measures help:
- Request collapsing: an edge sends one origin request for a segment and makes other viewers wait for that response.
- An origin shield: a middle caching tier that all edges fetch from, so the origin sees one request per segment.
Playlists need a TTL of about one segment duration or less. A stale playlist makes players stall because they cannot see new segments. Segments can be cached for much longer, since their content never changes.
Reliability
A VOD job can be retried. A live feed cannot. Common safeguards are:
- Accept two ingest streams (primary and backup) and switch if one stops.
- Run transcoders in two zones, producing identical segment numbering.
- Archive segments to object storage as they are created.
Exercise
A live stream uses 6-second segments and the player starts 3 segments behind the live edge. About how much delay comes from this buffering alone? What segment duration would bring it to about 6 seconds, and what is one cost of that change?
Show answer
3 × 6 = 18 seconds. With 2-second segments, 3 × 2 = 6 seconds. The cost is more requests to the CDN and origin, and slightly lower compression efficiency because keyframes occur more often.