CricInfo

Live Cricket Score Platform

Design the scoring core of a live cricket site: a scorer enters each ball, the system applies the Laws (extras, overs, strike, dismissals), keeps the scorecard, supports corrections, and pushes updates to viewers.

Overview

A live cricket site shows a scorecard that changes with every ball. Behind it, an official scorer enters each delivery: who bowled it, how many runs were made, whether it was a wide or a no ball, and whether a batter was out. The system must turn that stream of balls into the score, each batter's runs and balls, each bowler's figures, whose turn it is to face, and the result.

The problem tests three things. First, domain modeling: cricket has rules that change the count in awkward ways (a wide adds a run but is not one of the six balls of an over), and your classes must hold them in one place. Second, a source of truth: if the ball log is the truth and every figure is derived from it, a scorer's correction is simply 'remove the last ball and replay'. Third, the read side: one scorer writes, and very many viewers read, so updates are pushed to subscribers rather than recomputed per viewer.

A strong answer says 'the ball log is the truth' early, puts format rules (overs per innings, overs per bowler) in data, validates each ball against the Laws, and shows a correction in a test.

Scoping the problem

Start with questions, because each answer decides a part of the design. Here are the seven to ask, why each matters, and the usual answer.

  • Which formats? Their limits differ. Build T20 and one-day in the core, and leave Test as a follow-up.
  • Which extras? Each one changes the count differently. Model the wide, the no ball, the bye and the leg bye.
  • Which dismissals? Some are not allowed off a wide or a no ball. Model bowled, caught, lbw, stumped, hit wicket and run out.
  • Can the scorer correct a ball? The answer decides whether state is stored or derived. It is yes: the scorer can undo the last ball.
  • How many writers per match? This decides the lock. There is one scorer and there are many readers.
  • How do viewers get updates? By push or by poll. Push a snapshot after each ball.
  • Career statistics, commentary, tournaments? Each is a separate read model, so they are follow-ups.

Functional requirements

  • Formats as data: overs per innings and the most overs one bowler may bowl (T20I 20 and 4; ODI 50 and 10)
  • record(delivery): bowler, runs, extra (wide, no ball, bye, leg bye) and an optional dismissal
  • Validate each ball: innings not over, no consecutive overs, bowler quota, same bowler within an over, dismissal allowed for that extra
  • Keep the scorecard: total, wickets, overs, extras, each batter's runs and balls, each bowler's balls, runs and wickets
  • Rotate the strike on odd runs and at the end of each over; bring in the next batter after a wicket
  • End an innings when all out, overs are used up, or the target is reached; set the result
  • undo() removes the last ball; subscribers receive a snapshot after every change

Non-functional requirements

  • The ball log is the only stored state; every figure is derived, so a correction can never leave figures out of step
  • One lock per match makes record and read atomic: a reader never sees half a ball
  • Subscribers are called outside the lock with a snapshot, so a slow viewer cannot block the scorer
  • A new format is a new Format record; no scoring code changes
  • Recording a ball is O(1); undo replays the innings, O(balls)

Interview questions

  • The scorer entered a 3 that was really a 2. How do you correct it?
  • How do millions of viewers get the score without overloading the server?
  • How would you add Test matches?
  • How do you compute career statistics across matches?
  • Two scorers or a scorer and an admin tool write at once. What breaks?

Sign up free to read the full topic

More Low-Level Design topics

Start free on Cariara · Coding problems · System design studio