List functional requirements for the system (Ask the chat bot for hints if stuck.)...
List non-functional requirements for the system...
Performance: The system must provide real-time updates efficiently without lagging, regardless of user volume.
Availability: The system should have minimal downtime to ensure users can continuously access live updates and player stats.
Partition Tolerance: The system should continue to function even if some components fail or become unreachable.
Scalability: The ability to efficiently scale horizontally to handle increased loads during peak usage periods.
Eventual Consistency: The system can allow for data updates to be delivered in an eventually consistent manner rather than requiring immediate consistency.
Estimate the scale of the system you are going to design...
Define what APIs are expected from the system...
All request would have to include an authorization header with the correct jwt token:
POST /accountsDescription: Create a new user account.POST /accounts/loginDescription: Authenticate a user and return a JWT.POST /teams/favoriteDescription: Add a favorite team for the authenticated user.POST /gamesDescription: Create a new game.GET /stats?player_id={player_id}Description: Retrieve stats for a specific player.GET /stats?game_id={game_id}Description: Retrieve stats associated with a specific game.GET /events?game_id={game_id}&limit=10&offset=0Description: Retrieve all events that occurred during a specific game.GET /timeline?game_id={game_id}Description: Retrieve a chronological timeline of game events.Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
id (string, Primary Key)username (string, unique)email (string, unique)password_hash (string)favorite_teams (array of strings)id (string, Primary Key)name (string)type (string) - e.g., team vs. individual sportsid (string, Primary Key)sport_id (string, Foreign Key referencing Sports)team1_id (string, Foreign Key referencing Teams)team2_id (string, Foreign Key referencing Teams)start_time (datetime)status (string) - e.g., ongoing, finished, scheduledid (string, Primary Key)name (string)team_id (string, Foreign Key referencing Teams)position (string){ "player_id": "123", "game_id": "456", "stats": { "points": 20, "rebounds": 5, "assists": 8 }}{ "event_id": "789", "game_id": "456", "event_type": "score", "timestamp": "2023-09-20T12:00:00Z", "player_id": "123", "description": "Player 123 scored a 3-pointer"}email:username (if applicable):type:sport_id:team1_id and team2_id (if applicable):team_id:position:You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
POST /events to accept game updates.GET /timeline?game_id={game_id} to retrieve the timeline data.Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
The LRU cache is ideal for storing timelines for the most popular games because it automatically removes the least recently accessed items when the cache reaches its capacity. This keeps frequently requested timelines readily available, optimizing performance.
game_idCheck Cache
Cache Hit
Cache Miss
Fetch Data from RDBMS
Store in Cache
Return Timeline
Client Request
LRU Cache
Return Timeline
Fetch Data from NoSQL
Build Timeline
Update LRU Cache
Using a server-push model via WebSockets allows the server to send updates to clients as events occur, maintaining a seamless and responsive user experience.
Establish WebSocket
Process Event
Listen for Events
Push Updates
Deliver to
Client
WebSocket Server
Event Processing Service
Message Queue
Real-Time Notification Service
Explain any trade offs you have made and why you made certain tech choices...
By opting for NoSQL and a pub/sub model, you’ve made architectural choices that prioritize flexibility, performance, and scalability, which are essential in a real-time sports updating system. However, this comes with the necessity to balance consistency, potential complexity, and the management of event reliability.
Try to discuss as many failure scenarios/bottlenecks as possible.
A key component (such as a central server or a microservice) fails without redundancy, leading to a total service outage.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?