Hey Elixir Community,
I am trying to create a simple application where users can create a lobby to play turn based games like chess, scribble , poker etc with their friends and it also should has a feature so that other users can spectate the game. For spectate feature I am using MQTT broker and each spectator subscribes to game topic. Game topics are like game_topic/{game_id}. For players I am using socket.io to implement realtime event passing but there are certain limitations with socket io , like if two users are connected to different WS servers how will they pass events to each other. I know I can use something like signalling server or redis (for pub/sub) but if I am going to use pub/sub I thought why don’t I give elixir a try.
This is the current architecture:
For the new one I am thinking I should just create a new elixir service where for each user connection we spin up a process which will be responsible to pass events to user frontend client using pub/sub. This is the new architecture:
I am thinking of creating a process for each lobby, and that process should hold all the connected users and should also decide the turn of the users in some order and similarly the process could hold the current state of game so if any new new move is made by any new user (like moving pawn from e2->e4) I can just make changes in the chess FEN string and publish it to mongoDB. I have not worked with elixir earlier. Any suggestions/resources on how can I implement something like this would be really appreciated. Thanks for reading