Currently, I am developing a cryptocurrency-based betting game project. My database of choice is mongodb and I utilize mongoose for interaction with it. Within this database, I have a collection that houses documents detailing various betting games. Each document includes a field labeled “expires” indicating a deadline typically set to 3 minutes after creation. After this expiration date has passed, no additional bets can be placed, prompting the execution of a function to finalize the game: performing necessary calculations to determine a winner and marking the game status as inactive. To ensure only one active game exists in the database, I employ a partial index on the alive field. However, I am uncertain about the best strategy to automatically end games once their expiration dates are reached.
Potential solutions under consideration include: * Running a dedicated node instance to monitor the active game and its expiry status at intervals ranging from 1-3 seconds. * Scheduling the execution of the game-ending function immediately following the introduction of the expiry date.
Could there be alternative methods to address this issue more effectively? Is my current game design appropriate, or did I err in the implementation of this functionality? Would an approach involving storing the game object in memory until completion before saving yield better results?