I'm creating an action based rpg (not really realtime), where player can build it's own city and move his hero on a tile map.
Background:
I have such collections:
Scenario:
To move a hero, I should:
Then:
Problem:
My main concern about whole process, is that city after finding and before subtracting gold can be changed by another action (i.e claim gold action which just adds gold in city by atomic $add on city document).
Of course some request blocking is done at frontend, but game server is just api so everyone can fire 20 same requests at the same time and cause desynchronization of data. Is there anything which can be done or am I supersensitive?
Ps. Everywhere where we work on one document we use update or findOneAndUpdate (with $set,$add etc.), to omit finding, changing record in callback and then saving.