Event handlers within BC

110 views
Skip to first unread message

Daniel Abreu

unread,
Oct 14, 2017, 12:06:36 PM10/14/17
to DDD/CQRS
Hi guys!
I am struggling with the following:
Within my BC there are 2 aggregate roots, when A
is created there is an event being produced. There
is an event handler within that BC that
receives the event and creates B.
What I am missing is, what happens if the system
crashes before event handler for (A_wascreated)
was called. (I am using event sourcing and an inmemory bus).

Do I need a read model with catch-up subscription that produces commands to create B?

Thanks

Rickard Öberg

unread,
Oct 14, 2017, 7:22:59 PM10/14/17
to ddd...@googlegroups.com
Sounds like it, yeah. Since the event handling is not transactional
with store the event, you pretty much have to do it like that. The
read model, for just the above case, might just be the point in the
event log, so catchup works. I have a Logstash handler for EventStore
that does just that: store the current log position and forward events
to ElasticSearch. On crash the handler reads the file with the
position and restarts.

/Rickard

Peter Hageus

unread,
Oct 15, 2017, 4:00:10 AM10/15/17
to ddd...@googlegroups.com
Have a look at the Competing Consumers in EventStore. It’s a useful pattern with a single consumer as well. (You can build a single threaded version yourself with a checkpoint saved after each event handled).

/Peter
> --
> You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.
> Visit this group at https://groups.google.com/group/dddcqrs.
> For more options, visit https://groups.google.com/d/optout.

stefan.o...@googlemail.com

unread,
Oct 15, 2017, 4:31:12 AM10/15/17
to DDD/CQRS
Hi,


what happens if the system
crashes before event handler for (A_wascreated)
was called.

Nothing happens, and this is not even a problem. When you rebuild the system later, B will be created once A_wascreated is reprocessed (I'm assuming that your aggregates do not cause side effects). To me the answer is not adding more technology to fix this problem, but remove technology to make the problem go away: consider getting rid of your inmemory bus, and have aggregate B catch up with events directly from the event store.

Beware that you might be building a distributed monolith rather than a loosely coupled system if you continue on the path you are on.

Regards,

Stefan 
Reply all
Reply to author
Forward
0 new messages