My question is fairly simple but maybe hard to answer. I'm currently building my own game server and I've done to login server now. So, on to the actual game server. I have a question for this server though. Say, a thousand players are moving around on this server, how do I manage this with the database (MySQL) that should hold the player positions and such?

I understand I can't query the database every time something small changes or a single player moves because that would be a huge load for that server. How is this done in real game servers? When do they read or write to the database?

  • 2
    \$\begingroup\$ Why should the db be updating their positions? That should be kept in ram until they logout or disconnect. DB should be for persistent data but you should cache as much as you can into ram. \$\endgroup\$
    – jmasterx
    Commented Jan 4, 2014 at 14:12

1 Answer 1


Database access is always an expensive operation. For that reason it should be minimized as much as possible.

In an ideal case, you would read and write the player data once per session: When the client connects you read it, and when the client disconnects, you write the changed data back. In the meantime it should be kept in the memory of the gameserver.

But in practice you can never be sure that your gameserver never crashes, so you should do regular backup saves to the database so players don't lose too much progress when your network admin stumbles over the servers power cord. Once every few minutes is usually enough.

  • 1
    \$\begingroup\$ The basic rule for periodic saving of transient data like positions is "how many pissed players do I want to deal with when they lose N number of minutes of gameplay?" The basic rule for permanent data like items gained or big choices made is the same except replace minutes with seconds =) Many recent games seem to fall on the 5 minute mark, from personal experience with crash roll-backs and reloading to play again. \$\endgroup\$ Commented Jan 4, 2014 at 22:12
  • \$\begingroup\$ Phillipp is there a design where I can avoid rollbacks if the app crashes, with lets say 2000 players online, and not kill the database? Any link you could give would be nice. I believe a player losing a single item is bad. \$\endgroup\$
    – Gam
    Commented Apr 24, 2016 at 17:14
  • \$\begingroup\$ @Phantom When you are so worried about the impact of a rollback of just a few minutes of game time, then you seem to expect this to happen very frequently. In that case you might want to work on the stability of your server. \$\endgroup\$
    – Philipp
    Commented Apr 24, 2016 at 17:30
  • \$\begingroup\$ @Philipp It's not like that. Even if the server "dies" once in a year, and those "few minutes of lost game time" means people lost items that are worth 300$ (some are), that's freaking bad. A server's source code being handled by multiple persons, it's hard to make sure all of them do not mess it up. \$\endgroup\$
    – Gam
    Commented Apr 24, 2016 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .