Frontend School

Real-time Live Sports Scoreboard Frontend

System Design
medium

Real-time Live Sports Scoreboard Frontend

Medium
Frontend
System Design
Real-time
WebSockets
Performance
Scalability
State Management
UI/UX

Overview

Zerodha aims to expand its user engagement beyond financial markets by exploring dynamic content platforms. A critical component for any content platform is real-time data visualization. This problem challenges you to design the frontend architecture for a highly responsive and scalable live sports scoreboard, a feature crucial for engaging a broad user base with up-to-the-minute information.

What you need to do / Task

Design the client-side architecture for a real-time live sports scoreboard. Your design should focus on efficiently consuming, processing, and rendering live score updates for multiple concurrent matches, ensuring a smooth and low-latency user experience.

Scenario

Imagine a user opens a Zerodha-branded sports portal or a dedicated section within the existing Kite platform. They navigate to the 'Live Matches' section and are immediately presented with a list of ongoing cricket matches. As the matches progress, scores, overs, wickets, and other critical events update instantaneously on their screen, reflecting the live action without any noticeable delay. The user can switch between matches, and the displayed information remains consistently up-to-date and accurate.

Constraints

Constraints & assumptions

  • Data Source: A reliable, high-throughput WebSocket API provides structured JSON updates for ongoing matches. Assume the backend handles data aggregation and fan-out efficiently.
  • Update Frequency: During peak match action, updates can arrive at rates up to 50-100 messages per second per match.
  • Concurrent Matches: A single user might view a dashboard displaying 10-20 live matches simultaneously.
  • Concurrent Users: The system must support millions of concurrent users.
  • Latency: Perceived latency from event occurrence to UI update should be minimized (ideally < 500ms).
  • Client Resources: The solution must be performant on typical modern desktop and mobile browsers, minimizing CPU and memory footprint.
  • Technology Stack: Assume a modern frontend framework (e.g., React, Vue, Angular) can be used, but justify your choices.
  • Scope: Focus entirely on the frontend (browser-side) system design. Backend API implementation, database, and infrastructure are out of scope.

Out of scope

  • Detailed UI/UX design (focus on architectural patterns).
  • User authentication, authorization, or personalization features.
  • Offline mode or persistent caching across sessions.
  • Backend service design or database schema.
  • Push notification systems.

What interviewers evaluate

  • Ability to design a robust, scalable, and performant frontend architecture for real-time data.
  • Understanding of state management, data flow, and rendering optimizations in a high-frequency update environment.
  • Proficiency in identifying and mitigating potential bottlenecks and failure points.
  • Justification of technology choices and architectural trade-offs.

Requirements

1.

Design an efficient mechanism for consuming and processing high-frequency real-time updates from a WebSocket feed.

2.

Propose a robust client-side state management architecture that ensures data consistency and minimizes re-renders for multiple concurrent matches.

3.

Detail strategies for optimizing UI rendering performance to maintain a fluid user experience during rapid data updates.

4.

Outline a resilient error handling and reconnection strategy for WebSocket disconnections and potential data inconsistencies.

5.

Describe how the system will normalize and manage data from potentially different sports or varying schemas for extensibility.

6.

Discuss specific techniques to minimize client-side resource consumption (CPU, memory) under heavy load.

7.

Justify technology choices (framework, state management library, real-time client) based on the problem's constraints and requirements.

Design Brief

Design Brief: Real-time Live Sports Scoreboard Frontend

Your task is to design the frontend system for a real-time live sports scoreboard. This system needs to consume high-frequency updates, maintain consistent state, and render a dynamic user interface that provides an instantaneous view of ongoing matches.

Core Requirements & Functionality

  1. Real-time Data Consumption: The frontend must connect to a WebSocket endpoint (wss://sports.zerodha.com/live-scores) which streams JSON updates for various matches. Each update contains granular event data (e.g., score changes, wicket falls, over completions, player statistics). The data schema for different sports (e.g., cricket, football) might vary, but for this problem, focus primarily on cricket updates with a simple, normalized structure.

    • Example Cricket Update (simplified):
      {
        "matchId": "CRK-IND-AUS-2023-01",
        "type": "scoreUpdate",
        "timestamp": 1678886400000,
        "data": {
          "team1": {"name": "India", "score": "150/3", "overs": "25.2"},
          "team2": {"name": "Australia", "score": "149/5", "overs": "24.5"},
          "currentBatters": ["Virat Kohli", "Rohit Sharma"],
          "currentBowler": "Pat Cummins",
          "lastBallEvent": "Four runs by Kohli"
        }
      }
      
  2. Dashboard View: Display a list of 10-20 active matches. Each match card should show essential information: match name, current score, overs, wickets, and a brief highlight of the most recent event.

  3. Detail View (Optional but consider): When a user clicks on a match card, they can navigate to a detailed view showing more granular information, such as ball-by-ball commentary, full scorecard, player statistics, etc. (Focus on the data flow implications for this, not UI details).

  4. Performance & Responsiveness: The UI must remain fluid and responsive even during periods of high update frequency. Updates should be reflected on the screen with minimal lag, without causing UI jank or excessive resource consumption.

  5. Robustness & Error Handling: The system should gracefully handle WebSocket disconnections, re-establish connections, and manage potential out-of-order or malformed data packets. It should provide feedback to the user if data is temporarily unavailable.

Design Considerations

As you design, consider the following aspects and be prepared to discuss the trade-offs involved:

  • Data Flow: How will data flow from the WebSocket, through your application's logic, to the UI components?
  • State Management: What patterns or libraries will you use to manage the global and local state of multiple matches? How will you ensure consistency and prevent stale data?
  • Rendering Strategy: How will you efficiently update only the changed parts of the UI? Consider techniques like virtual DOM, memoization, or selective re-rendering.
  • Scalability (Client-side): How will your design scale to handle more matches, more detailed information, or even different sports with varying data structures in the future?
  • Performance Optimizations: Discuss specific techniques to reduce CPU cycles, memory usage, and improve perceived performance (e.g., throttling, debouncing, data normalization, immutable data structures).
  • Error Recovery: Strategies for dealing with network instability, WebSocket failures, and data parsing errors.
  • Technology Choices: Justify your choice of frontend framework (e.g., React, Vue, Angular) and any specific libraries for state management (e.g., Redux, Zustand, Vuex) or real-time communication (e.g., ws library, socket.io-client).

Present your design using diagrams (e.g., component hierarchy, data flow, architecture overview) and explain your choices clearly. Be ready to discuss alternatives and trade-offs.

Loading editor...