Design a Cricbuzz mobile plugin that keeps fetching current score.
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-05-09
Problem Statement
Design a mobile plugin/module for cricket fans that continuously fetches and displays live cricket scores. The focus is on object-oriented design, modularity, data fetching, caching, and update strategies.
✅ Functional Requirements
1.Match Information
•Display live scores for ongoing matches.
•Show match details: teams, innings, overs, wickets, run rate.
•Support multiple formats: ODI, T20, Test matches.
2.Real-Time Updates
•Continuously fetch live scores from a backend service or public API.
•Update UI at a configurable interval (e.g., every 5 seconds).
•Efficiently handle multiple matches simultaneously.
3.Caching & Offline Support
•Cache the last fetched score to reduce API calls.
•Display last known score if offline.
4.Notification (Optional)
•Notify user on significant events: wickets, milestones, match end.
🔐 Constraints & Assumptions
•Assume mobile environment with intermittent network.
•Focus on LLD, data fetching, caching, and update mechanism, not the UI.
•Plugin should be lightweight to avoid excessive battery or network usage.
•Backend service provides score updates via REST API or WebSocket.
🧱 Key Components & Classes
1.Match Class
1
2class Match {
3private:
4 int matchId;
5 string teamA;
6 string teamB;
7 int scoreA;
8 int scoreB;
9 int wicketsA;
10 int wicketsB;
11 int oversA;
12 int oversB;
13public:
14 void updateScore(int scoreA, int scoreB, int wicketsA, int wicketsB, int oversA, int oversB);
15};1.ScoreFetcher Class
1
2class ScoreFetcher {
3private:
4 string apiEndpoint;
5 int fetchInterval; // in seconds
6public:
7 Match fetchScore(int matchId);
8 void startFetching();
9 void stopFetching();
10};1.ScoreCache Class
1
2class ScoreCache {
3private:
4 unordered_map<int, Match> cachedScores; // matchId -> Match
5public:
6 void updateCache(Match match);
7 Match getCachedScore(int matchId);
8};1.NotificationService (Optional)
•Sends notifications to users based on score changes or milestones.
2.PluginController Class
1
2class PluginController {
3private:
4 vector<int> subscribedMatches;
5 ScoreFetcher fetcher;
6 ScoreCache cache;
7public:
8 void subscribeMatch(int matchId);
9 void unsubscribeMatch(int matchId);
10 void displayScore(int matchId);
11};🔄 Example Workflow
1.User subscribes to a match: subscribeMatch(matchId).
2.ScoreFetcher periodically fetches live score from backend API.
3.Score is updated in ScoreCache.
4.Plugin displays the latest score from cache.
5.Optional: NotificationService triggers alerts for significant events.
🧪 Expected Deliverables
•Class diagram showing Match, ScoreFetcher, ScoreCache, PluginController, and NotificationService.
•Implementation of fetching, caching, and subscription management.
•Test cases:
•Fetching score for a match
•Handling offline cache
•Subscribing/unsubscribing to matches
•Notifications for score changes
💡 Discussion Points
•Trade-offs: polling interval vs network usage.
•Caching strategies for efficient updates and offline support.
•Scalability for multiple concurrent matches.
•Extensibility for supporting other match metadata or formats.