10 milliion users
1 million DAU, 5 games so 5 million games per day. 50 games per second. 1 move per 5 seconds.
10 QPS for games, 10x higher on peak times, 100 QPS potential
Storage
The key design to get right is the games themselves. These need to be extremly fast for blitz 5 minutes, game, where say a half second lag would be extremely jarring.
To minimize latency and the needed network bandwidth we will use websockets. The two client devices will connect to a gaming server that will host one of the games. They will send a json message like
{type: "entrance", user: "bob"} to enter the game and then send messages for each move {type: move, piece: "knight1", user: "bob", to: "F5"}
Given these two moves the server will continually store the current game state, manage the connection between both, and validate then update the game state.
Workflow
game creation -> assign user colors -> start game ->
server recieves move -> validates move -> updates game state
update game state then leads either to server is ready to recieve another move or game is over
Websocket storage
even with 1000 games memory is not a bottle neck. validation should also be extremely quick sub 1 ms, and should therefore not be a bottleneck either. Network time will be the bottleneck
We probably could squeeze all these games onto one server but we would want to have a load balancer that is distrubted by region to minimize network travel time & would want redudnant servers for failures.
Game complete Workflow
User profile
Game matching service
user:
game:
Redis memory cached data
active_game:
create_move(player, piece_id, to_coordinates): websocket message when a move is made
create_game_request(player_elo, player_geolocation)
list_games(player_id)
list_moves(player_id, game_id)
Websocket game
Game matcing service should send new games to servers with the frewst # of current games. Or else create new servers on threshold