Design a Live Sports Scoreboard – Frontend System Design

We’ll walk through the frontend system design for a live sports scoreboard: a Sunday slate, a detail view with play-by-play, a clock that ticks on its own, and a score that stays right when the feed is late, duplicated, or out of order. The store applies every event immediately. The clock interpolates a snapshot. A running animation never owns the score.
This is not the Robinhood question. A quote ticker can throw away every price except the latest. It is also not Twitch chat, where dropping a message is fine. A scoreboard has to apply every scoring play, survive official corrections, and still look live. Correctness is the product. Latency is a preference you negotiate per field.
Problem Statement
Design the frontend for a live sports scoreboard like ESPN or Yahoo Sports.
Requirements:
- A multi-game dashboard with live scores and clocks
- A game detail view with play-by-play and a box score
- Scores stay correct when events arrive delayed, duplicated, or out of order
- The game clock keeps moving between feed messages, and pauses when the sport pauses
- Push updates with a poll fallback when the socket dies
- Score and play animations that never drop or reorder events
Describe the client architecture, the event model, clock sync, reconciliation, and how the UI stays honest under a bad feed.
Interviewers are checking three things. Do you treat the score as a value at a sequence number, or do you increment it like a counter? Do you know that a live clock and a live play-by-play are different streams with different freshness rules? And can you keep a dashboard of fifteen games at 60fps without putting every tick in React state?
Clarifying Questions
| # | Question | Interviewer’s Answer |
|---|---|---|
| 1 | Which sports on day one? | NBA and soccer. Mention NFL and MLB as follow-ups. The clock rules differ. |
| 2 | How many games on the dashboard? | A Sunday slate of about 15. The user opens one game in detail. |
| 3 | Official feed or unofficial / betting feed? | Official. A few seconds late is acceptable. A wrong score is not. |
| 4 | Do we sync to the TV broadcast delay? | No. Show official data as it arrives. A “spoilers” delay is a follow-up. |
| 5 | Betting, fantasy, or personalization? | Out of scope. The board is scores, clock, and plays. |
| 6 | How many concurrent viewers? | About 200,000 at a Finals tip. One tab watches 1–15 games. |
| 7 | Browsers and devices? | Evergreen desktop and mobile web. The phone is a first-class dashboard. |
Question 1 decides the clock. Basketball stops on every whistle and shows tenths in the last minute. Soccer runs continuously and then adds stoppage. One clock component with a running flag covers both. Question 3 is the design constraint: you optimize for an authoritative, slightly late stream, not for beating the TV by guessing. Question 6 tells you the fan-out is a backend problem. The client’s job is one multiplexed connection and a store that can take a burst.
Requirements
Functional
- Dashboard cards: teams, score, period, clock, and a short last-play line.
- Game detail: scrolling play-by-play, period scores, and a box score that updates in place.
- Apply scoring plays, non-scoring plays, clock messages, status changes, and official revisions.
- Show a “live” mark only while the feed is fresh. Show “delayed” or “final” otherwise.
- Subscribe and unsubscribe as the user filters the slate or opens a detail view.
- Recover after a dropped socket without a full page reload.
Non-Functional
- The visible score matches the latest contiguous sequence the client has applied. Never a guess.
- A scoring play is on screen within about 200ms of arriving at the tab, including a short reorder window.
- The dashboard stays at 60fps with 15 live clocks. Clock ticks do not re-render the React tree.
- Play-by-play memory is bounded. A finished game keeps a summary, not 600 DOM nodes forever.
- Hidden tabs back off. Visible live games stay current.
- Keyboard and screen-reader users get score and period changes without a firework of announcements.
The contiguous-sequence rule is the one that shapes the design. If you have 41 and 43 but not 42, you do not apply 43. A later basket is not more important than the free throw you have not seen. The store waits, or it loads a snapshot.
Napkin Math
| Metric | Estimate | Calculation | So what? |
|---|---|---|---|
| Events per NBA game | ~500 | ~150 possessions × ~3 feed lines, plus clock | Detail view is a few hundred rows, not a million. |
| One play payload | ~400 B | JSON with ids, seq, scoreAfter, text | A full game is ~200 KB. Keep it. Don’t paginate live plays. |
| Sunday slate, 15 live | ~7.5 KB/s | 15 × ~1 event/s × 400 B, plus heartbeats | One socket. The cost is apply + paint, not download. |
| Clock paint | 15 writes / 100ms | MM:SS until last minute, then tenths | Write textContent. 150 React renders/s would jank. |
| Reorder window | 400ms | One RTT plus feed jitter | Long enough to catch a swap, short enough to feel live. |
| Poll fallback | 2s live, 15s idle | One GET for the subscribed set | Worse than push, cheap enough that the tab stays correct. |
| Finals concurrency | 200k tabs | Fan-out is server-side | The client still opens one connection, not one per game. |
Architecture
The browser has four jobs, and they do not share a loop. Transport moves bytes. A sequence buffer puts them in order. A store applies them. Views read the store. The clock engine and the animation queue are views that happen to write the DOM themselves.
| Layer | Owns | Runs | Talks to |
|---|---|---|---|
| Transport | Socket, heartbeat, poll, reconnect | One per tab | Ingest, Snapshot API, SeqBuffer |
| SeqBuffer | Per-game held events and gap timers | On every inbound message | GameStore, Snapshot API |
| GameStore | Score, status, plays, lastAppliedSeq | Contiguous applies only | Subscribers |
| ClockEngine | Interpolated remaining time | rAF or 100ms | Store clock snapshots, card DOM |
| AnimationQueue | In-flight score and play motion | On score change | Store (read), DOM (write) |
| React views | Layout, filters, play list chrome | On discrete store changes | GameStore.subscribe |
There is no React context holding the clock, and no reducer that does score + 3. Both fail the first time the feed repeats a play or skips one. Fifteen clocks at ten updates a second is 150 renders if the ticking string lives in state. The play list does not need to know that a second ticked.
“The store is a projection of the highest contiguous sequence. The clock is a snapshot I interpolate. Animations read the store; they never write it.”
Data Model
Every live field is versioned by a per-game sequence number. The official feed assigns it. The client never invents one.
export type GameId = string;
export type Seq = number;
export type GameStatus = "scheduled" | "live" | "delayed" | "final";
export interface Score {
readonly home: number;
readonly away: number;
readonly seq: Seq;
}
export interface GameClock {
readonly period: number;
readonly label: string; // "Q4", "OT", "2H +4"
readonly remainingMs: number;
readonly running: boolean;
readonly tenths: boolean; // last minute of NBA, etc.
readonly serverNow: number; // epoch ms on the feed host
}
export interface PlayEvent {
readonly id: string;
readonly gameId: GameId;
readonly seq: Seq;
readonly type: "play" | "score" | "revision" | "clock" | "status";
readonly text: string;
readonly scoreAfter?: Score;
readonly revisesId?: string;
readonly clock: GameClock;
}
export interface GameSnapshot {
readonly gameId: GameId;
readonly seq: Seq;
readonly status: GameStatus;
readonly score: Score;
readonly clock: GameClock;
}
export interface GameState {
readonly gameId: GameId;
readonly status: GameStatus;
readonly score: Score;
readonly clock: GameClock;
readonly lastAppliedSeq: Seq;
readonly plays: readonly PlayEvent[];
}
Three choices are worth defending.
Score is a value, not a delta. A scoring play carries scoreAfter. You assign it. You do not add 3 to whatever you last showed. Addition double-counts a retransmit and goes wrong forever after a gap. The sequence number on the score is the same sequence as the play that produced it, so a stale score cannot overwrite a newer one.
Revisions are new events. A reversed basket is not a silent edit of play 41. It is play 88 with type: "revision" and revisesId. The play list keeps the original line and marks it overturned. The score jumps to scoreAfter on 88. History stays auditable, and late joiners who only have a snapshot still land on the corrected score.
The clock is not derived from wall time. Tip-off plus 48 minutes is wrong the first time the referee stops play. The feed sends remaining time, a running flag, and the host’s clock. The client interpolates from that snapshot until the next one arrives.
Ingest: Push First, Poll When It Goes Quiet
The tab opens one connection and sends the set of gameIds it cares about. Compact subscriptions (the dashboard) get score, clock, and status. The open detail view also gets plays. Changing the filter or opening a game is a subscribe message, not a new socket.
WebSocket is the default because subscribe and unsubscribe are client-to-server messages. SSE is a strong alternative if the set lives in the URL: EventSource reconnects on its own and sends Last-Event-ID, which maps onto lastAppliedSeq. Mention both. Pick one and put a poll under it.
A transport object owns the connection. It takes four inputs: the current game ids, a per-game last-applied sequence, an events callback, and a delta fetcher. Its behavior:
- Open: reset the missed-heartbeat counter and send one subscribe message with the game ids and an
aftercursor built from each game’s last applied sequence. - Message: reset the counter and pass any events to the callback. The transport never interprets scores.
- Heartbeat: every 5 seconds, count a miss. Two misses in a row close the socket and drop to fallback.
- Fallback: fetch the delta since the cursor, apply it, and reconnect with exponential backoff capped at 30 seconds. While live, the poll runs about every 2 seconds.
Close on a missed heartbeat. Do not wait for onclose. Half-open sockets are common on mobile radios: TCP looks fine, bytes have stopped. Poll is a delta from lastAppliedSeq, GET /scoreboard?ids=g1,g2&after=g1:1842,g2:990, not a full refresh and not a reload that throws away the play list. After poll applied 1847, reconnect with that cursor. Hidden tabs slow the poll via visibilitychange; the first visible frame polls once, then resumes push. Bundle the slate into one GET with ETag. Fifteen parallel polls is how one user becomes a thundering herd.
Event Reordering and Score Reconciliation
Feeds lie about order. A play that happened first can arrive second because it crossed a different ingest worker, or because a correction was sent before the original. The client’s job is to make that boring.
Each game gets its own sequence buffer and two pure reducers.
- Buffer. It expects
lastAppliedSeq + 1. A lower sequence is a duplicate and gets dropped. A higher one goes into a hold map and arms one 400ms gap timer. The expected event applies together with every held event that follows it contiguously, as one batch, and clears the timer. If the timer fires, the buffer asks for a snapshot. - Apply snapshot. A snapshot older than the store is ignored. Otherwise status, score, clock, and
lastAppliedSeqcome from the snapshot, and plays above its sequence are trimmed. - Apply events. Skip anything at or below the last applied sequence. For the rest, advance the sequence, take status from status events, assign
scoreAfterwhen present, replace the clock, and prepend non-clock plays to a list capped at 250.
A snapshot at 43 when you are at 43 is a confirm. A snapshot at 40 is junk from a cache or a slow replica. Never merge a stale snapshot into a newer store. That is how a corrected score gets undone by a polite CDN. When the gap timer fires, ask for a snapshot, not “event 42 please”. Official feeds skip numbers. After the snapshot applies, drop held events at or below N and keep the ones above. Same seq is a duplicate and you ignore it. Same id with a new seq is a revision: key the play list by id, the store by seq.
Latency versus correctness
Applying 43 while 42 is missing feels faster and then the score goes 98, 102, 99. Prefer latency on the clock (interpolate; 200ms off is invisible, a one-second rewind is not), on a last-play line you have already applied, and on non-scoring chrome like a possession arrow. Do not prefer it on the score, on period or “Final”, or on a revision. The feed is already late. The 400ms buffer is not what makes the user miss a basket. Applying out of order is what makes them distrust the product.
The Game Clock
Candidates start a setInterval at tip-off and subtract. That dies on the first whistle. Treat each clock message as a snapshot: running means remainingMs - (now - serverNow), stopped means frozen remainingMs. The next message replaces it.
The clock engine has three small parts. One computes the remaining time, frozen when stopped and remainingMs - (now - serverNow) when running, floored at zero. One formats it as m:ss, or m:ss.t when the snapshot sets tenths, rounding up so the display never reads 0:00 while time remains. One binds a DOM node to a requestAnimationFrame loop that reads the latest clock snapshot, writes the label and time as text, and returns an unbind function.
serverNow is the host time when that remaining value was true. Transit then cancels out of the subtraction. Receive time alone runs the clock fast by one hop on every message. Do not put the formatted string in React state. Bind each card’s clock to a ref. React re-renders the card on score, status, or period. Seconds are not discrete events.
Sport rules sit in the snapshot. NBA flips running on every whistle and sets tenths under a minute. Soccer stays running; stoppage is a label like 2H +4, not a timer you invent. NFL is two snapshots: game clock uses remaining-ms, play clock can be last-write-wins. Ignore a clock message with a lower seq even if it shows more time. A paused 1:24.3 is newer than a running 1:25 if the sequence says so.
Multi-Game Dashboard
The dashboard is a list of compact-mode cards. The detail route adds that gameId to the detail set. One store, two readers. Off-screen cards unbind their clock rAF and drop play subscriptions. Finished games unsubscribe so the socket goes quiet. Batch store notifications to the next animation frame so eight scores in one second are one React pass. The clock engine already paints on rAF and stays out of that batch.
The game store is a framework-free singleton: a map from game id to state, plus a listener set. It exposes get, apply(gameId, events), replace(snapshot), and subscribe. Apply and replace run the pure reducers and ignore unknown games. Instead of notifying synchronously, they set a flag and schedule one notification on the next animation frame, so a burst of events costs a single React pass. Components read it through useSyncExternalStore, so each card re-renders only when its own game changes.
Seed the store from the first HTTP payload so the first paint is not a skeleton. The socket applies anything newer than those snapshot sequence numbers. If a live game goes quiet for about 15 seconds, flip LIVE to DELAYED. Users treat that pill as a correctness guarantee.
Animations That Do Not Drop Events
The failure mode is treating a CSS transition as the apply step: you flip 95 to 98, 42 and 43 arrive, the transition finishes, and you paint 98 because that is what the animation closed over. The store already had 100-103. Invert it. Apply 41, 42, and 43 before the first frame of motion. If a new score arrives mid-flip, cancel and paint from the current pixels to the latest store value. Intermediate scores never get a turn.
A score animator belongs to each card’s score node and remembers the last score it painted.
- A score with a lower sequence than the painted one is ignored. Equal digits just update the painted sequence.
- A real change cancels any running animation, writes the new text immediately, and runs a short opacity pulse (about 220ms) with the Web Animations API. Reduced motion skips the pulse and paints.
- Finish records the new score as painted. Cancel only fixes the pixels. It never writes to the store.
Cancel is not drop. Play 41 already updated lastAppliedSeq. The next update reads the latest score. Queueing every flip turns a review sequence into a cartoon of wrong scores. oncancel must not write an old score back into the store, and animation callbacks must never dispatch. Play rows use the same split: insert the data immediately, animate the newest row or none. A list that waits for transitionend falls behind and then dumps a backlog. prefers-reduced-motion snaps. The store path does not change.
State and Data Flow
Boot, live, and recovery are three different reads of the same store.
- First paint. HTTP snapshot for the subscribed slate. Cards render scores and a frozen clock. No socket yet.
- Bind. ClockEngine attaches to the card nodes. Transport opens and subscribes with
after: lastAppliedSeqfrom those snapshots. - Live. Events go through SeqBuffer. Contiguous runs call
store.apply. Clock messages replace the snapshot the interpolator is using. Score changes notify React and the animator. - Gap. Buffer holds the future, starts the 400ms timer, and asks for a snapshot if the hole remains. The score on screen stays at the last contiguous value.
- Socket death. Transport polls deltas. The store cannot tell push from poll. That is deliberate.
- Foreground. On
visibilitychangeto visible, poll once immediately, then reconnect push. The clock recomputes from the last snapshot plus elapsed host time. You do not “catch up” by spinning the interpolator through the hidden minutes if the period ended while you were away. You wait for the snapshot.
Undo does not exist. The user is not editing. The closest thing is an official revision, and that is just another event with a higher sequence.
API
// HTTP
GET /api/scoreboard?ids=g1,g2 // 200 { data: GameSnapshot[] }
GET /api/games/:id // snapshot + last N plays
GET /api/games/:id/events?after=1842 // 200 { data: PlayEvent[], snapshot?: GameSnapshot }
GET /api/scoreboard?ids=g1,g2&after=g1:1842,g2:990
// Push (WebSocket or SSE)
Client -> { type: "subscribe", gameIds, after: Record<GameId, Seq>, mode: "compact" | "detail" }
Client -> { type: "unsubscribe", gameIds }
Server -> { type: "events", events: PlayEvent[] }
Server -> { type: "snapshot", data: GameSnapshot }
Server -> { type: "ping", serverNow: number }
The snapshot on the events endpoint is recovery, not a poll payload. Prefer serverNow on the clock snapshot; a ping offset is a fallback for soccer halves that rarely send clock messages. Do not open a second socket for detail. Mode is a flag. Compact events omit play text.
Optimizations
| Problem | Technique | Effect |
|---|---|---|
| 15 clocks janking React | rAF + textContent on a ref |
Zero reconciles per tick |
| Burst of eight games | Coalesce store notifies on rAF | One React pass per frame |
| Off-screen cards | Unbind clock, unsubscribe plays | Less work, fewer bytes |
| Finished games | Drop the live subscription | Socket goes quiet after the slate ends |
| Large play lists | Cap at ~250 live rows, window the rest | Bounded memory on a 3-hour game |
| Poll of a quiet slate | One GET, ETag, 304 | No payload when nothing happened |
| Mobile radio sleep | Heartbeat timeout, then poll | No stuck LIVE badge |
Logos should be a sprite or cached SVGs, not 30 PNGs on first paint. In the Performance panel you want short apply tasks and a clock that never shows up as scripting. If ScoreBoard renders 10 times a second, the clock leaked into React.
Handling Edge Cases
- Retransmit.
seq <= lastAppliedSeq. Drop it. Do not flash last-play. - Hole that never fills. Gap timer, then snapshot. Discard held events at or below that seq.
- Correction after paint. Revision event. Cancel the flip, snap to
scoreAfter, mark the old row overturned. - Delay or weather. Status event,
running: false, change the badge. Stop interpolating. - Period ends mid-tick. A clock message with
remainingMs: 0andrunning: falsewins over 200ms the interpolator still has. - Finished game. HTTP snapshot only. Live play lists stay unpaginated; archives can page.
- Two tabs. Two sockets, two stores. There is no local write. Skip
BroadcastChannel. - Clock past zero. Clamp. A negative clock is a screenshot.
- Stale snapshot after failover. Ignore anything below
lastAppliedSeq.
Test traces, not just components: 41, 43, 42, snapshot 43. Assert the store after each step and that the UI never painted 43’s last-play before 42. Replay a revision, a poll gap, and a paused 1:24 beating a late running 1:25 with a lower seq.
Accessibility and Security
Accessibility
- Live regions. One polite region per open game. Announce score and period, not ticks or rebounds.
- Motion and color. Flips respect
prefers-reduced-motion. Winning team is bold or labelled, not green alone. LIVE / DELAYED / FINAL are text. - Cards are links to the detail route. The clock node is not a button. Tenths still need 4.5:1 contrast.
Security
- Play text is untrusted. Render as text, never
innerHTML. gameIdis an allowlisted id, not a path fragment concatenated onto a host.- Authenticate the socket with a short-lived token or a cookie, not a long-lived token in a query string.
What a Strong Answer Sounds Like
| Topic | Junior answer | Senior answer |
|---|---|---|
| Score | setScore(s => s + 3) |
Assign scoreAfter at a seq. Never increment. |
| Order | Apply events as they arrive | Per-game buffer, gap timer, snapshot replaces holes |
| Clock | setInterval from tip-off |
Interpolate a snapshot. running is the pause bit. |
| Transport | “Use WebSockets” | One multiplexed push, heartbeat, delta poll, resume cursor |
| Animation | CSS transition on the score | Store first. Cancel in-flight flips. Paint latest. |
| Dashboard | Context + one render per tick | rAF clocks, coalesced store notifies, compact vs detail |
For a live stream where dropping messages is the right call, see Design Twitch. For a ticker where only the latest value matters, see Design Robinhood. This question sits between them: every scoring play matters, and the latest snapshot still wins a fight with the past.
Conclusion: How to Design a Live Sports Scoreboard
Start with the sequence number. The official feed is the authority, the store is a projection of the highest contiguous seq, and a snapshot is how you recover a hole. Scores are assigned, not added. Revisions are new events. That single model absorbs duplicates, swaps, and corrections without a special case for each sport.
Then split the streams that only look similar on the page. The clock is a snapshot you interpolate and paint outside React. Play-by-play is an append-only list with a cap. The dashboard is a compact subscription. Push carries all of it until a heartbeat fails, then one delta poll keeps the store honest and the socket resumes from the same cursor. If you can explain why you would rather show a slightly old score than a newer one you cannot prove is next in line, and why a cancelled flip is not a dropped basket, you have answered the question the interviewer is actually asking.
