System Design: How to handle concurrency?
I have little sde background, so apologies for noob question. I was recently asked in a System Design interview to design a system that will get hundreds of thousands of hits within a short time span (think multiplayer online short video game). The main challenge is to handle concurrency issue. I gave a standard answer, "have multiple application servers and sync server with replicated cache and write locks on db". But interviewer was disappointed and also mentioned it in the feedback. I'm curious to learn how to actually answer questions like this. Could some Blind ninja please spare a few minutes to answer?
Edit: You're supposed to design a game where there is no limit to the number of users (open to make assumptions here). Each player is looking to uncover treasures on the game map. So each player should also get a consistent copy of the game map and current state. This is not a turn-based game.
p.s. I understand that grokking course and that book and those YouTube channels are the best way to learn. But I'm looking for keywords for this answer so I can directly read those topics and be able to get this out of my head.
Tc: 280k
comments
- async/await (I.e. event loops) to handle incoming requests
- message queues to decouple critical actions from non-critical actions
- use distributed data layers (e.g. redis, cassandra, spanner)
- consider alternatives to threads such as Java Fiber or Goroutines
Clients update state changes at regular intervals which gets written to an event stream. Many player moves are non conflicting and can happen concurrently. Those that are conflicting, needs to be totally ordered and causal. The client side logic can either be pessimistic or optimistic when dealing with conflicting changes. The state changes are persisted as an event stream, that allows for fault tolerance.
The server determines the actual state in presence of conflicts and writes the updates to another stream that needs to be fanned out to clients.
(I have no idea how multiplayer games are actually built)
What if they disconnect for a while and join again?
How will you check if someone have left the game?