DEV Community

Cover image for Building a Live Scoreboard with a Real-Time Sports Data API (REST + WebSocket)
Vijay Choudhary
Vijay Choudhary

Posted on

Building a Live Scoreboard with a Real-Time Sports Data API (REST + WebSocket)

Building a Live Scoreboard with a Real-Time Sports Data API

If you've ever tried to build something that shows live sports scores
or odds updating in real time, you've probably hit the same wall I did:
REST polling works fine until it doesn't. Poll every 5 seconds and your
data is stale during the moments that matter most. Poll every 500ms and
you're hammering an API (and your own backend) for no good reason.

The fix is combining REST for initial state with WebSocket for live
updates — and it's a pattern worth understanding even outside sports data.

The problem with polling

A typical naive implementation looks like this:

\javascript
setInterval(async () => {
const res = await fetch('/api/scores/live');
const data = await res.json();
renderScoreboard(data);
}, 5000);
\
\

This works, but it has three real problems:

  • Latency: your UI is always up to 5 seconds behind reality
  • Waste: you're re-fetching full payloads even when nothing changed
  • Scale: every client polling independently multiplies load fast

A better pattern: REST for state, WebSocket for deltas

Fetch the initial snapshot once, then subscribe to a socket for updates:

\`javascript
// 1. Get initial state via REST
const initial = await fetch('/api/scores/live').then(r => r.json());
renderScoreboard(initial);

// 2. Subscribe to live updates via WebSocket
const socket = new WebSocket('wss://your-data-provider/live');

socket.onmessage = (event) => {
const update = JSON.parse(event.data);
applyDelta(update); // patch only what changed
};
`\

This cuts your latency from seconds to milliseconds, and your backend
only pushes data when something actually changes — no wasted requests.

Where this gets hard

The tricky part isn't the code above, it's the data source underneath
it. A few things that matter more than people expect:

  • Sub-200ms latency during peak load (dozens of concurrent live matches), not just in a quiet test environment
  • Reconnect handling — sockets drop, and your client needs to reconcile state cleanly when it comes back
  • Coverage depth — plenty of providers cover the top 5 sports well and fall apart on the long tail (table tennis, esports, horse racing)

I've been working with Tech Magnetics
for exactly this — a real-time sports data API covering 100+ sports and
15,000+ leagues via REST and WebSocket, built for the sub-200ms/peak-load
case rather than the demo case. They have a free sandbox if you want to
try the pattern above against real live data instead of mocked responses.

Wrapping up

If you're building anything with live data — sports, finance, IoT — the
REST-plus-WebSocket pattern above generalizes well beyond this one use
case. Happy to answer questions in the comments if you're working
through something similar.

Top comments (0)