I had 2 create a lobby service for online gaming service like teen patti or online poker games.
The system will have lobby which can have at most 5 players
A user can search for a lobby on Type and Prize Money.
Assign the user to lobby with minimum empty slots.
This is how i went about it.
LobbyService-- Will have basic CRUD. Any new lobby will pushed to cache.
The cache will have
a. lobbyId
b. currentCapacity
c. createdOn
Matcher Service
Result findAvailableLobby(GameType gameType,Int prizeMoney)
Result
a. boolean status // Indicates lobby found or not
b. String lobbyId
Aggregator Service :This will check with the matcher service if there is any lobby available for a user entered gametype and prize money. If yes it will add user to the lobby and update the currentCapacity in the cache. If the current capacity is 5 it remove from the cache and start the game.
If the status is false from the matcher service it will ask lobbyService to create a new lobby.
allocateLobby(String userID,GameType gameType, int prizeMoney)
As for the assign lobbyWith minimum empty slots my matcher service will always return the oldest createdOn lobby , this way I am implicitly handling the condition.
All the services are communicating insync.
I did tell that due to load my aggregator service and matcher service can have queues in between to communicate to handle load.
Guys kindly tell me as to what i've missed in this design