Can I defer a message in an event stream for later consumption (in a rational way)?
*Why do this with GES? *
I want to make my system CQRS/ES structured, and I want the underlying systems to be as simple as possible. It is clear to me that I can do what I want with EventStore+MessageQueue, but I’d love to have a EventStore-only solution.
Why do I want to defer messages?
I envision a scenerio where I’m putting in “Buy” orders. The command to buy can be sent in a number of times, but I want to reject/fail buys that take the user’s cash balance below zero.
So far my modelling looks like (BuyOrderCreatedEvent)->(BuyOrderExecutedEvent|BuyOrderRejectedEvent)->(BuyOrderRecorded).
If the sequence is Created->Executed->Recorded, Created->Executed->Recorded, Created->Executed->Recorded, there is no problem. But Created,Created,Created->Executed,Executed,Executed,Recorded,Recorded,Recorded might create a state where the resultant cash balance goes below zero.
For this reason, I think the handler that transitions between Created and Executed|Rejected should only process after there are no orders that are between Executed and Recorded; only the first BuyOrderCreatedEvent can be processed until it has a corresponding Rejected/Recorded event processed.
With a Message Queue, I would check that I’m up to date on processing messages for the aggregate, then only process the Created message if there are no Executed messages dangling. If there is a dangler, I would tell the Queue to defer the message and send it to me in a few seconds, then move forward in the queue until I got a BuyOrderRecorded to clear the BuyOrderExecutedEvent.
Is my modelling incorrect, is there a way of deferring events in GES, or should I just bit the bullet and pull a Message Queue into my solution?
Thanks,
Josh