I am writing a game title in javascript, and also to prevent cheating, i am getting the overall game be performed around the server (it is a game just like a more difficult checkers). Since the overall game is rather complex, I have to keep gamestate to be able to validate client actions.

Can you really keep gamestate in memory? Is the fact that wise? Must I do this? If that's the case, how? I'm not sure how that will work.

I'm also able to store in redis. Which kind of factor is fairly familiar in my experience as well as no explanation. But when I actually do store in redis, however , on each and every move, the overall game will have to obtain the data from redis and interpret and parse that data to be able to recreate the gamestate on your own. Consider moves happen often this appears very stupid in my experience.

What must i do?

Should you really, really do not want the overhead of I/O then just store the overall game condition inside a global object keyed by the overall game id:

var global_gamesate = {}

After that time each connection check what the overall game id would be to retrieve he game condition:

var gamestate = global_gamestate[game_id];

Most probably you have a mechanism to map client periods to game id.

Usually, game condition is small , would hardly occupy much RAM. Let us be pessimistic and assume each game condition occupies 500K. You'll be able to serve 2 million games (4 million customers when we assume two customers per game) for every gigabyte of RAM in your server.


However, I must explain that databases like MySQL already implement caching (that is configurable) so loading probably the most commonly used data essentially loads from RAM having a minor socket I/O overhead. The benefits of databases is you can cash more data than you've RAM simply because they keep relaxation on disk.

In case your program ever reaches the burden in which you start considering writing your personal disk-serialization formula to implement a swap file then you are essentially re-inventing the wheel. By which situation I'd say opt for databases.