Hello,
I have a question about when and how properly to put version of aggregate inside command that is designed for it.
I think that the following example should show what I’m interested in.
Consider an EventSourced aggregate:
`
class Wallet {
lateinit var id: WalletId
var availableCoins = 0
fun handle(cmd: AddCoins) {
apply(addedEvent)
}
fun handle(cmd: RemoveCoins) {
apply(removedEvt)
}
//… basic creation things, event sourcing handlers etc
}
`
In the distributed scenario, let’s suppose that i cannot prove synchronous operation based on the command bus of axon server, at some point there might be situation where RemoveCoins could be executed twice at the same time using the same aggregate version which would end up creating race condition.
The question is, how do i ensure in distributed scenario that the command handler will be handled on the latest version, meaning before handling the command i can provide it current aggregate version, so at the point in time of dispatching until handling the version should not change if this command is meant to be handled. How do i load current aggregate version without listening to every event that it publishes? Is there an easy way around it?