Bird
Raised Fist0

ESPNcricinfo System - Match, Innings, Ball, Scorecard, Commentary

LLDmediumInterview freq: medium
Choose your preparation mode4 modes available
🏗️
ESPNcricinfo System - Match, Innings, Ball, Scorecard, Commentary
Design a cricket match tracking system with detailed ball-by-ball data, innings, scorecards, and commentary.
mediumAdvanced LLD ChallengesFreq: medium
Prerequisites:OOP FundamentalsJava Concurrency BasicsDesign Patterns (Factory, Observer, Composite)
⚙️
Functional Requirements
  • Track each ball's details: runs, extras, wickets, bowler, batsman
  • Maintain innings with ordered balls and cumulative scores
  • Generate scorecards reflecting current match state
  • Allow live commentary updates linked to specific balls
  • Support concurrent updates from scorers and commentators
  • Persist match data for retrieval and analysis
  • Provide APIs for viewers to fetch live and historical data
👤
Use Cases
  • Record ball-by-ball events during a match
  • Generate and update innings and match scorecards in real-time
  • Add and update live commentary for each ball
  • Retrieve match summary and detailed statistics
  • Handle multiple matches concurrently
  • Support querying historical match data
🧑‍💻
Actors
  • Viewer
  • Commentator
  • Scorer
  • System Administrator
❓
Clarifying Questions to Ask
  • How many concurrent matches and scorers/commentators are expected to update the system simultaneously?
  • Should the system support partial updates or rollbacks for ball data in case of errors?
  • Is there a pricing or subscription model affecting data access or update frequency?
  • How to handle edge cases like interrupted matches, super overs, or abandoned innings?
  • What is the expected latency for live commentary and scorecard updates?
  • Are there any constraints on data storage or retention policies?
Out of Scope
✗ User authentication and authorization
✗ Video streaming or live broadcast integration
✗ Complex analytics or predictive modeling
✗ Mobile app UI design
⚡
QPS Calculation
read qps5000
write qps1000
commentEstimated queries per second based on concurrent viewers and scorers.
🖥️
Server Estimate
app servers5
db servers3
commentServers estimated to handle load with redundancy.
🔢
Enumerations
enum BallType
LEGAL | WIDE | NO_BALL | BYE | LEG_BYE
Defines the type of ball delivery to prevent typo bugs and enable exhaustive switch-case handling for scoring logic.
enum WicketType
BOWLED | CAUGHT | RUN_OUT | LBW | STUMPED | HIT_WICKET | OBSTRUCTING_FIELD
Enumerates wicket dismissal types to ensure consistent representation and facilitate wicket-specific processing.
enum MatchStatus
NOT_STARTED | IN_PROGRESS | PAUSED | COMPLETED | ABANDONED
Tracks match lifecycle states to control permissible operations and UI display logic.
enum PlayerRole
BATSMAN | BOWLER | ALL_ROUNDER | WICKET_KEEPER
Defines player roles to support role-based statistics and validations.
📦
Match
6 fields
private final String matchIdprivate volatile MatchStatus statusprivate final List<Innings> inningsListprivate final String teamAprivate final String teamBprivate final Date startTime
Manage overall match lifecycle, maintain innings sequence, and provide match-level summary and status.
public synchronized void startMatch()Atomically sets match status to IN_PROGRESS if NOT_STARTED.
public synchronized void addInnings(Innings innings)Adds a new innings to the match ensuring thread-safe update of innings list.
public synchronized Innings getCurrentInnings()Returns the latest innings in progress or null if none.
public synchronized Scorecard getScorecard()Generates a consolidated scorecard for all innings.
📦
Innings
6 fields
private final int inningsNumberprivate final List<Ball> ballsprivate volatile int totalRunsprivate volatile int wicketsLostprivate final String battingTeamprivate final String bowlingTeam
Track ball-by-ball events, maintain cumulative runs and wickets, and provide innings-level statistics.
public synchronized void addBall(Ball ball)Atomically appends a ball to the innings and updates runs and wickets.
public synchronized int getTotalRuns()Returns the current total runs scored in the innings.
public synchronized int getWicketsLost()Returns the current number of wickets lost.
public synchronized List<Ball> getBalls()Returns a copy of the ball list to prevent concurrent modification.
📦
Ball
9 fields
private final int overNumberprivate final int ballNumberprivate final BallType ballTypeprivate final Player batsmanprivate final Player bowlerprivate final int runsScoredprivate final boolean isWicketprivate final WicketType wicketTypeprivate final String commentary
Represent a single ball delivery with all relevant details including runs, wicket info, and commentary.
public String getSummary()Returns a textual summary of the ball event.
📦
Scorecard
3 fields
private final Map<String, Integer> teamRunsprivate final Map<String, Integer> teamWicketsprivate final Map<String, List<PlayerStats>> playerStatsMap
Aggregate and present match and player statistics for display or export.
public synchronized void updateFromInnings(Innings innings)Updates scorecard data based on the latest innings data.
public synchronized int getTeamRuns(String teamName)Returns total runs scored by a team.
📦
Commentary
5 fields
private final String commentaryIdprivate final int overNumberprivate final int ballNumberprivate volatile String textprivate final Date timestamp
Store and update live commentary text linked to a specific ball event.
public synchronized void updateText(String newText)Atomically updates commentary text to ensure consistency.
public synchronized String getText()Returns the current commentary text.
📦
Player
4 fields
private final String playerIdprivate final String nameprivate final PlayerRole roleprivate final String team
Represent a player with identity and role information.
public String getName()Returns the player's name.
public PlayerRole getRole()Returns the player's role.
🗄️
matches
PK: matchId
matchId STRINGteamA STRINGteamB STRINGstatus STRINGstartTime TIMESTAMP
Stores match metadata and status.
🗄️
balls
PK: matchId
matchId STRINGinningsNumber INToverNumber INTballNumber INTballType STRINGbatsmanId STRINGbowlerId STRINGrunsScored INTisWicket BOOLEANwicketType STRINGcommentaryId STRING
Stores ball-by-ball details for each match and innings.
🔌
GET
/match/{matchId}/scorecard
Request
{
  "matchId": "String"
}
Response
{
  "scorecard": "Scorecard object with team and player stats"
}
Fetches the current scorecard for a given match.
🔌
POST
/match/{matchId}/innings/{inningsNumber}/ball
Request
{
  "matchId": "String",
  "inningsNumber": "int",
  "ball": "Ball object with delivery details"
}
Response
{
  "status": "success or failure"
}
Records a new ball event for the specified innings.
🔌
PUT
/match/{matchId}/commentary/{overNumber}/{ballNumber}
Request
{
  "matchId": "String",
  "overNumber": "int",
  "ballNumber": "int",
  "text": "String"
}
Response
{
  "status": "success or failure"
}
Updates live commentary text for a specific ball.

Practice

(1/5)
1. In designing the Post entity, should Post be an abstract class or an interface, considering it has state like content and timestamp? Why?
easy
A. Abstract class, because it can hold shared state and provide default behavior.
B. Abstract class, because interfaces cannot have any methods.
C. Interface, because state can be stored externally in a database, so no need in class.
D. Interface, because it allows multiple inheritance and defines behavior only.

Solution

  1. Step 1: Analyze state and behavior requirements

    Post has state fields like content and timestamp, which require storage within the class.
  2. Step 2: Abstract class vs interface capabilities

    Abstract classes can hold state and provide default method implementations, while interfaces (pre-Java 8) cannot hold state and primarily define behavior.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Stateful entity -> abstract class preferred over interface [check]
Hint: Stateful entity? Use abstract class, not interface [check]
Common Mistakes:
2. A class has a private constructor and a clone() method that returns a copy of itself. Which design pattern is applied here and why is this the correct use case?
easy
A. Builder pattern, because it separates object construction from representation
B. Singleton pattern, because it restricts instantiation to one object
C. Factory pattern, because it creates objects through a factory method
D. Prototype pattern, because cloning avoids expensive object construction

Solution

  1. Step 1: Identify the pattern from constructor and clone()

    The private constructor prevents direct instantiation, and the presence of a clone() method indicates object copying rather than new creation.
  2. Step 2: Match pattern intent to scenario

    The Prototype pattern is used to clone objects when construction is expensive, which fits the scenario. Singleton restricts to one instance, Factory creates new instances, and Builder separates construction steps.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Private constructor + clone() -> Prototype pattern [check]
Hint: Private constructor + clone() means Prototype pattern [check]
Common Mistakes:
3. In a UML class diagram, should Vehicle be modeled as an abstract class or an interface if it has state like speed and behavior like accelerate()? Why?
easy
A. Interface, because it allows multiple inheritance and defines behavior without state.
B. Abstract class, because it can hold shared state and provide default behavior implementations.
C. Interface, because state can be stored externally and behavior defined via default methods.
D. Abstract class, because interfaces cannot declare methods with parameters.

Solution

  1. Step 1: Analyze state and behavior requirements

    Vehicle has state (speed) and behavior (accelerate()), so it needs a construct that supports instance variables and method implementations.
  2. Step 2: Evaluate abstract class vs interface

    Abstract classes can hold state and provide default behavior; interfaces cannot hold instance state (only constants) and default methods can't maintain state.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    State + behavior with shared code -> abstract class [check]
Hint: Stateful base class -> abstract class, not interface [check]
Common Mistakes:
4. In the Amazon Locker Service, if the assignLocker() method is not synchronized, which exact sequence of thread interleaving causes two packages to be assigned the same locker?
medium
A. Thread 1 assigns locker and updates status; Thread 2 waits until Thread 1 finishes, then assigns a different locker.
B. Thread 1 and Thread 2 both call assignLocker() simultaneously and both fail to find any available lockers.
C. Thread 1 checks locker availability -> true, context switch; Thread 2 checks availability -> true; both assign the same locker before status update.
D. Thread 1 releases a locker; Thread 2 immediately assigns it without checking availability.

Solution

  1. Step 1: Identify the check-then-act race condition

    Without synchronization, Thread 1 reads locker as available, then context switches before marking it occupied.
  2. Step 2: Thread 2 also reads locker as available and proceeds to assign it, causing double-booking.

    Both threads assign the same locker before either updates the status.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Check-then-act gap -> double assignment [check]
Hint: Check availability -> context switch -> both assign same locker [check]
Common Mistakes:
5. In a parking lot system, the parkVehicle() method checks if a spot is available and then marks it occupied. Without synchronized, what exact thread interleaving causes double-booking?
medium
A. Thread 1 parks vehicle, Thread 2 waits until Thread 1 finishes, then parks.
B. Thread 1 checks spot availability -> true, context switch; Thread 2 checks availability -> true; both mark spot occupied.
C. Thread 1 marks spot occupied, Thread 2 checks availability -> false, no double-booking.
D. Thread 1 and Thread 2 both crash simultaneously causing no booking.

Solution

  1. Step 1: Identify the check-then-act race condition

    Without synchronization, Thread 1 reads spot as available but before marking occupied, context switches to Thread 2 which also reads available.
  2. Step 2: Both threads proceed to mark the spot occupied independently

    This leads to double-booking as both think the spot was free at check time.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Check-then-act gap -> both threads see available -> double-booking [check]
Hint: Check-then-act without sync -> double-booking race [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard