When running live campus broadcasts for events like convocation or debates, stream availability matters. If an upstream encoder suffers packet loss or disconnects, the video player needs to recover immediately without leaving viewers on a frozen screen.

1. Three-Tier Failover Architecture

Standard HTTP Live Streaming (HLS) delivers media in short 2- to 6-second segments listed in an .m3u8 playlist. When an encoder goes offline, default players simply stall. In Campus TV, we handle this with a three-tier fallback pipeline:

The player continuously monitors segment requests. If two consecutive chunks fail with a 404 or connection timeout, the Video.js player switches to the backup ingest stream without re-mounting the DOM.
Architecture: Stream Failover Cascade
graph TD A["Client Video.js Player"] -->|"1. Primary HLS M3U8"| B["Primary Edge Ingest"] B -.->|"Fail / Timeout"| C{"Failover Controller"} C -->|"2. Backup HLS M3U8"| D["Secondary Server"] D -.->|"Fail / Offline"| E["3. YouTube Archive Stream"]

2. Real-Time Viewer Tracking with Socket.IO

Instead of polling the database to keep track of active viewers, we read live room occupancy directly from Socket.IO:

io.on('connection', (socket) => {
  socket.on('live:join', () => {
    socket.join('live_broadcast');
    const count = io.sockets.adapter.rooms.get('live_broadcast')?.size || 0;
    io.to('live_broadcast').emit('live:viewers', { active: count });
  });

  socket.on('disconnect', () => {
    const count = io.sockets.adapter.rooms.get('live_broadcast')?.size || 0;
    io.emit('live:viewers', { active: count });
  });
});

3. Buffer Delay & Latency

End-to-end broadcast latency in HTTP chunked delivery depends directly on segment duration and the client buffer depth:

To minimize latency during live events, set OBS or FFmpeg keyframe intervals to 1.0 second with 2.0-second HLS segments. This keeps edge latency under 5.5 seconds while still letting CDN caches work efficiently.

4. Summary

Handling failovers on the client and keeping lightweight fallback streams ready ensures viewers get uninterrupted live coverage, even during unexpected network hiccups.