Time Based Events : Broad approaches

We have domains built from streams. For things going overdue (Time based event raising), we have a worker that looks at all the events and handles creation of an overdue event.
However we recently had a scenario that the worker took a bit longer to run and raised an overdue event out of sequence because the live domain objects state had changed.

We are looking for any advice on how to handle such scenarios, articles, experience, pointers appreciated.


In our case we have time based publishing of content, as it can be set
to be published on a particular date. The way we do it is to have the
publish event with the time, and then we update the read model to both
have a boolean that is true, and a publish date. All read models then
filter on both these fields to check for availability, so there's no
need to fire an event at that exact time.

In your case, an explicit event might be necessary. The simplest way I
can think of is to make the worker's job as fast as possible. On
publishing the thing that can become overdue, insert it into a linked
list in the read model with position based on time. Then the worker
only has to check the head of the list to figure out if any domain
objects are overdue. If so, continue down the list. O(1) complexity
basically. Would that be possible for you?


That makes sense :slight_smile: