I recently got intrested in event sourcing. In the examples I saw they often use a bank as an example to display the possibilities.
What I often see is that they store events like Deposited{5}, Withdrawn{10}, etc.
This felt logical at first. Until I started thinking about commands that failed. They might not have an event, so I start loosing information.
So I thought about storing the commands besides the events. So something like Deposit{5}, Withdraw{10}, etc
But these commands do not affect the state. So they don’t belong in the same stream of data as the events I’m storing.
All pretty clear. But still it felt a little bit weird storing stuff double like this. One for the command and then more or less the same for the event.
Then I was thinking about the events. Although the user wanted to deposit 5 euro, the result is a new value for the balance of the account?
So command: Deposit{5}
Event: BalanceUpdated{105} (knowing balance was 100)
command: Withdraw{10}
Event: BalanceUpdated{95}
I can store a link to the command in the metadata of the event to see it was a deposit and a withdrawel. Why should or shouldn’t I store it like this? For things like owner we also store the new value of the object that we want to change. Why not for something like the balance?