Users should be able to create a game session
Users should be able to make moves
Users should be able to get real time updates of the moves and chat
Users should be able to join and leave the game seamlessly
Users should be able to view leaderboard
Highly consistent : Both users should get a consistent view of the game
Availability : System should be highly available
Scalability : System should be able to handle thousands of concurrent players
Low-latency : System should display each move within a couple of milliseconds
Fault tolerant : System should work as expected even if one or more of its components fail
Reliability and Durability : Game data, User data, leaderboard data and all other data should not be lost and should be reliable
Total Users : 10 million
DAU : ~1 million
Games per day per active user : ~2
Moves per game : ~30
Requests per day : ~1 million * 2 * 30
QPS : ~(1 million * 2 * 30)/24*60*60
Each User Data is ~1KB
Total user data : ~1KB * 10M
Each move data : ~1KB
Total move data : ~1KB * (1 million * 2 * 30)
User Management APIs : Users should be able to create accounts, update information, login, logout.
Game operation APIs : Users making moves, users fetching leaderboard
Move Validation APIs : Validation of moves made by the users according to chess rules
Result APIs : Declaring win/lose/draw results for users
Leaderboard View API : Provide consolidated and ordered ranking of users based on their game history
User Data and Game Data : For User and Game data we will use MySQL data because it is structured and provides consistency which is one of our most important non functional requirements
Move Data : For Move data will use MySQL data because it is structured and provides consistency which is one of our most important non functional requirements
Leaderboard Data : For leaderboard data, we will use Redis Sorted Set which does the aggregation and order ranking of users based on game data. This will reduce the load on our Relational databases.
Client/AI opponent : We can have AI opponent for single player games.
Load Balancer : Use load balancers to handle server failures, make our system fault tolerant and handle the load efficiently in peak traffic hours.
Frontend Application Server : This server will have User Interface and Game Interface to faciliate various actions for the players.
Websocket : This will maintain connection between backend and frontend server and provide real time communication between the servers.
Backend Application Server : This will have Game Creation, Move APIs, Move validation APIs and all the APIs providing various functionality. Backend server will also communicate with the databases for persistence and data retrieval. It will also communicate with the Redis sorted server for leaderboard data.
MySQL Database : This will have User, Game and Move data.
Redis sorted set : This will have leaderboard data.
Client sends request to the load balancer.Load balancer sends this request to the frontend server.Frontend server sends the request to the backend server.Websocket maintains connection between frontend and backend servers and facilitates real time data updates.Backend server communicates with databases and Redis sorted set.
1) Websocket for real time updates and communication
In online chess game, it is of prime importance to have real time updates communicated to users in order to provide a dynamic online game Experience. Without this, it would be a bad experience for the users if they are not updated about the opponent's moves immediately. So websocket is one of the most important components for performance and low latency user experience.
2) Redis Sorted Set
Users view the leaderboard which is a ranking of users based on their game history. This task needs fetching data, aggregating it and rank users accordingly. This puts loads on the databases, which is why Redis sorted set can help reduce the load on databases and provide leaderboard view to the users.
We have prioritized consistency over availability as rendering a consistent view to all players is of utmost importance to provide an enjoyable experience to users.
We should have failover mechanism for websocket server as well. If it fails, then the communication between backend and frontend servers will increase latency and our most important functionality of real time updates and consistent view will also fail.
We can work on providing customized features to users to make it more appealing to users, like color patterns on the UI. Also, we can add a feature to allow users to share their game results with the online chess community and other social networks.