Currenty i'm working on creating a chess app with nodejs & socket.io
now the running games information are stored in an array like this:
games[token] = {
'creator': socket,
'players': [],
'interval': null,
'timeout': timeout,
'FEN' : '',
'PGN' : ''
};
The question is : Is better to save games info to DB at the creation of games and change the values of fields move by move, or save every game after finish? Which is better approach?
if you wait until the end of a game to save state then you run the risk of losing it if something like a server crash occurs. Think unhandled exception or something outside of your control like a container restart or something worse.
Persist every bit of data that you want recoverable as soon as possible. I could imagine an rpg in which it wasn't super important to always be able to recover the players exact position on a map. It seems you'd always want to be able to recover the state of your chess games.