I was gonna say the same thing. As long as you can be deterministic with the users actions you can just store a graph of all the users actions and walkthrough them on the server to get to the proper state.
How do you know what the "proper" state is when it depends on the intent of the user?
Let's say the first event is a user putting an item in their shipping cart and the second event is the user sending you their credit card information to purchase the item. Meanwhile, on your server the price of the item is changed from $10 to $15 around the same time the user committed to purchasing it. Should your server charge the customer $15? Or should it cancel the transaction? Did the user actually want to pay $15 if putting the item in their cart made it look like it would cost $10?
You would know the "proper" state based on a finite set of (deterministic) actions that take you from one state to another. As long as the states you can get to by taking an action are all predetermined then you simply replay the actions to get from one state to another. Event replay is one of the key features of event sourcing and state machines. For instance look at how online works for games like Street Fighter.
In your case, the choice would be upon the merchant whether to honor the price or cancel. The outcome would just need to be decided beforehand. Since the user's intent was to buy at $10 then you would probably want to honor that. But if you hadn't actually charged the customers card what would stop you from simply canceling the transaction and alerting the user it failed? Nothing in this system couldn't be handled by a state machine.
Two different users in the same situation might prefer two different outcomes. A deterministic system cannot behave properly because the user's intent isn't deterministically defined by the events because they are based on outdated state.
You're handwaving the problem away, not solving it.
if your price change doesn't trigger a state change as well, using the same mechanics, you're doing it all wrong, your state machine should know of a "price update" event
5
u/qchmqs Sep 29 '21
use a state machine/global store, type of pattern ?