Search code examples
load-balancingmultiplayer

How to maintain user and game state across different servers?


I have a multiplayer browser based quiz game built on php, javascript and MySQL. If I place load balancer and autoscaler to scale my game then I am concerned about how below scenario will be handled:

  1. A user is connected on server-1 and after some time drops off.
  2. Later when the player joins game, the load balancer send the request of this player to server-2.
  3. Then how will my player's previous data will be available now on server-2.

Basically what will be good option to maintain game and player state across different servers.


Solution

  • You can have different HTTP servers (for PHP and Javascript) without problems, but you need to have a single MySQL database. Then, it doesn't matter which PHP server is connected to the player, all servers just need to get the data from the same database.

    If you need to have different servers also for the database I suggest you to look at MySQL Clustering.