Preserve match states after server restart?

In match_terminate in the docs it seems all current matches are forcefully terminated when the server shuts down.

Is it possible to have list of matches preserved with their states?

I don’t want to save the state to player storage since it contains asymmetric data that they need to guess that I do not want them to access (bluffs they need to guess, etc). I’m also not sure it would be a good idea to save the whole match state to storage during match_loop since that’s a lot of unnecessary writes.

Does nakama have any internal mechanism to do this automatically?

When the server shuts down there is no choice but to stop running matches. The shutdown grace period gives you an opportunity to persist exactly as you want.

After receiving the termination signal you should notify players the match is stopping, save the state to a storage object, and stop the match. Use a system-owner storage object with read 0, write 0 permissions so users can’t read it. There’s no need to do this in the match loop, you can do it in the terminate hook itself.

Then when the match needs to resume load the storage object in match init and restore the in-memory match state from there.

1 Like

Thank you but how long should the shutdown grace period be to in order to save all the matches?

This depends on the matches you have running, as well as your infrastructure that the server runs on. This is why we’ve left this value configurable :slight_smile:

2 Likes