I’m playing with the thought to implement some same game using event sourcing to learn more about it.
Therefore I looked into the documentation of commanded and watched a talk about it. From the documentation and the talk it got pretty clear to me how I should model things that are constrained on one end like a bank withdrawal.
But how could one model transactions that are constrained on both ends?
In the context of the game the first thing came to my mind was a player dropping an item into a chest. The player needs to have the item in his inventory and it needs to fit in the receiving chest.
Currently, the only way I see after reading through commandeds documentation was to do it like this:
- create a command that moves the item from the inventory to the chest.
- check if the inventory contains the item in the execute function
- create the event to move it into the chest
- create the command that puts the item in the chest from the process manager
- check if there is enough space in the chest and for this example it is not
- Fire an event that rolls back the transaction
- get that one back into the process manager
But is this atomic? Or could there be a race and the player picked already up another item and doesn’t have room left in his inventory anymore?
Are there possibilities I currently do not see because I have no experience in this field?
Is there a way to get my flow from above atomic? (or is it already?)
Thanks in advance!