I’m trying to implement CQRS for a queue system where user can join a queue by clicking a button. The system will tell the user if queue is full.
When the user click the button, it raised the command and triggered event like “user queued at 07:00 AM”. The handler for this event then (asynchronously) add a new participant to the queue. It also updates the
full flag of the queue depending on how many participants in the queue. If the queue open for 1 hour, each participants get 5 minutes time slot, then it can hold 12 participants.
I would like to know which approach I should take when calculating the
now(): calculate the latest value, always query the latest state of the queue. If the command is “user queued at 07:00 AM” and now is “07:10 AM”, the
fullflag reflects the condition at “07:10 AM”. Looks like will cause a problem when replaying the event.
07:00 AM: Calculate it based on the state at 07:00 AM. This means queries are more complicated: need to know how many participants at 07:00 AM.
now()when handling the event then raising another event like “queue is full at 07:10”. This new event handler will eventually set the
fullflag instead of the current “user queued at 07:00 AM” event. Is event raising another event valid for this use-case?