XportAPI Global Video Infrastructure
Intermediate 7 min read

Handling source failover during a live match

Upstream sports feeds drop mid-match. Design the client so a failed source is a two-second interruption rather than a dead player: ranking sources, switching without a refetch, and what to show while it happens.

Reliability Failover Architecture

Assume the source will fail

Upstream signals are third-party. They drop, get throttled, degrade in quality, or disappear entirely in the middle of a match, and no amount of edge infrastructure prevents that — the edge can only make the switch fast and invisible.

This is why the stream resolver returns an array rather than a single URL. A client that reads sources[0] and discards the rest has thrown away the only thing that makes recovery possible without a user-visible failure.

Rank sources before you need them

Rank the array once at resolve time rather than deciding under pressure. The checkedAt timestamp tells you how recently each source passed a health probe, which is the strongest available signal. Beyond that, sources whose names indicate a higher tier broadcaster tend to be more stable.

Keeping the ranked list in memory means a failover is an array index increment, not a network round trip.

Freshness-first ranking javascript
function rankSources(sources) {
  return [...sources].sort((a, b) => {
    // Most recently verified first.
    const freshness =
      new Date(b.checkedAt).getTime() - new Date(a.checkedAt).getTime();
    if (Math.abs(freshness) > 30_000) return freshness;

    // Within the same probe window, prefer explicit HD labelling.
    const hd = (s) => (/\b(1080|fhd|hd)\b/i.test(s.name) ? 1 : 0);
    return hd(b) - hd(a);
  });
}

Switch without restarting the player

Destroying the Hls instance and building a new one costs a visible black frame and loses the buffer. Calling loadSource() on the existing instance reuses the media element and the decoder, and the viewer sees a short freeze instead of a reset.

Track attempts per source so a flapping feed cannot trap the loop. Three failures on one source means move on; exhausting the array means the match genuinely has no working signal, which is worth telling the user plainly rather than spinning forever.

Bounded failover over a ranked list javascript
class StreamSession {
  constructor(hls, sources) {
    this.hls = hls;
    this.sources = rankSources(sources);
    this.index = 0;
    this.attempts = 0;
  }

  current() {
    return this.sources[this.index];
  }

  failOver() {
    this.attempts += 1;

    // Give a source three chances before abandoning it.
    if (this.attempts < 3) {
      this.hls.loadSource(this.current().url);
      return true;
    }

    this.index += 1;
    this.attempts = 0;

    if (this.index >= this.sources.length) return false; // exhausted
    this.hls.loadSource(this.current().url);
    return true;
  }
}

What the viewer should see

A failover that takes two seconds and shows nothing reads as a bug. The same two seconds with a quiet "switching source" indicator reads as the system working, and the difference in support tickets is substantial.

Keep the message neutral and avoid naming the broadcaster. Do not surface the attempt count or the source name — it means nothing to a viewer and leaks more about your upstream than you want in a screenshot.

Frequently asked questions

How many redundant sources does a fixture usually have?
It varies by competition and by how much attention the fixture draws. Marquee matches in major leagues typically carry several; lower-tier fixtures may have one. The sourceCount field on the match object tells you before you resolve.
Should the client re-resolve the stream periodically?
Not on a timer. Re-resolve when the ranked array is exhausted, or if the user is still watching well past the point where the original tokens would have expired. Polling on a schedule adds load without improving reliability.
Does failover lose the viewer position?
For live content there is no position to lose — every source rejoins at the live edge. The visible cost is the buffer refill, which is why reusing the existing Hls instance rather than recreating it matters.

Continue reading

Direct Operator Provisioning

Ready to Power Your Sports Platform?

Standard security onboarding ready in 2 to 3 hours (API key issuance, domain whitelisting, and origin IP security lock). Custom enterprise setups ready within 1 to 3 days. Contact our enterprise operator directly.

Fast onboarding: 2–3 hours for key issuance, domain & IP lock (custom setups up to 3 days)
Custom league allocation (EPL, NBA, Liga 1, V.League, Saudi Pro League)
Tier-1 Global Anycast Edge Network (250+ PoPs, < 250ms TTFF worldwide)
Direct Channel

Start Live Inquiry

Average response time: < 15 minutes
WhatsApp (+1 917 724 2611)