India need 6 off the last ball. Twenty million people are staring at a score app instead of the TV, because the video stream is often 20-30 seconds behind and their friend on WhatsApp already knows. The bowler runs in. Within a second of the scorer at the ground tapping "SIX", every one of those 20 million screens should change.
The update itself is tiny: a few hundred bytes. The hard part is that it goes to everyone, at the same moment, every half a minute or so, for hours. This lab is about fan-out. You'll design it from a blank page. Try each step yourself before reading on.
The brief
You're building a live cricket score and commentary app, in the style of Cricbuzz. For each live match it shows the score, the current batters and bowler, the last few balls, and a ball-by-ball commentary feed written by a team of commentators.
Who uses it?
- Scorers at or near the ground, entering each ball into a scoring tool.
- Commentators writing a line or two for each ball.
- Fans, on phones and the website. Most are watching one match. In a big game they all arrive at once.
In scope: entering ball events, building the live scorecard, delivering updates to fans in real time, and loading the page for someone who joins mid-match.
Out of scope: push notifications for wickets when the app is closed (see the notifications lab), news articles, video, the full statistics archive, and ads.
Requirements
Functional
- Scorers record each ball: runs, extras, wickets, who bowled and who faced.
- Commentators attach text to balls.
- Fans see the live score and commentary update without refreshing.
- A fan who opens the app mid-match sees the current state immediately, then live updates.
- Mistakes can be corrected ("that was a leg bye, not a run"), and the correction reaches everyone.
Non-functional
- Fast: an update reaches 95% of connected fans within 2 seconds of the scorer submitting it.
- Massive fan-out: 20 million concurrent fans on one match.
- Ordered and complete: a fan never sees ball 18.4 after ball 18.5, and never misses a ball for long. If the score says 172 and the commentary says 178, trust is gone.
- Cheap per fan. The app is free and ad-funded. Cost per million viewers matters.
- Survives the spike when 10 million people open the app in the minute after a dramatic wicket.