I am currently developing an online real-time game which uses a global dictionary to store all the game rooms. If a user try to enter a game, the script checks the dictionary looking for an empty room. If no empty room is found, a new room object is added to the dictionary so other logged users can enter a game room.
The problem is that using a global dictionary for such task is not a good idea as pointed in these questions: Are global variables thread safe in flask? How do I share data between requests? and Preserving global state in a flask application
In the answers, it was recommended storing requests shared data in databases or memcached.. In case I wanted to do it using the database way, should I store the entire dict in the database every time it was requested? Is there a better and secure way to do this?