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 full
flag:
- Use
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”, thefull
flag reflects the condition at “07:10 AM”. Looks like will cause a problem when replaying the event. - Use
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. - Use
now()
when handling the event then raising another event like “queue is full at 07:10”. This new event handler will eventually set thefull
flag instead of the current “user queued at 07:00 AM” event. Is event raising another event valid for this use-case?