I can pair users with similar level to me to play a chess.
In a chess game, I can review all the steps I have gone through.
List non-functional requirements for the system...
Estimate the scale of the system you are going to design...
match()
stop_search()
play(x, y)
surrender()
UserTable
user_id
user_name
avatar
level
last_active_timestamp
num_matches
num_win
MatchTable
match_id
status
start_time
duration
num_steps
log_path
UserMatchTable
user_id:
match_id
win: boolean
When
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...
The users will connect to the server via socket. The server will maintain a cache for users that are seeking game matching. The cache will be a hashmap. The key is the user level and value is a deque of user_ids. We will also maintain a hashmap from user_id to the memory in the deque. When user is active (through socket) and the enabled searching, the user_id will be added to user_id cache. When user is no longer active, the socket has been broken, the user will be kicked from the queue.
If there are existing users waiting for matching, a match will be paired. Now, it will write an entry in match table and write two entries in user_match_table user match table.
Now, the users will be directed to Game Service. The Game Service could have multiple machines as the game could last long. The table could be using consistent hashing using match_id.
For each game, the game server will cache user_id and color in cache. It will write logs to ensure all the steps are captured. Each player should play by sequence. Once the game is finished, the Game Server will update user_match table and match_table. The logs could be asynchronously dump to the disk for persistence.
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?