Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the CQRS repository publishing events, not the event store?

Tags:

cqrs

According to http://cre8ivethought.com/blog/2009/11/12/cqrs--la-greg-young the component responsible for publishing events using an event publisher is the repository.

My question simply is: Why is that?

In this blog post we are told that:

The domain repository is responsible for publishing the events, this would normally be inside a single transaction together with storing the events in the event store.

I would have expected this as a task of the event store: Once an event (or multiple events) has been stored, it's published.

So why is it on the repository?

like image 217
Golo Roden Avatar asked Oct 01 '12 17:10

Golo Roden


People also ask

What is the difference between CQRS and Event Sourcing?

CQRS is implemented by a separation of responsibilities between commands and queries, and event sourcing is implemented by using the sequence of events to track changes in data.

Which is responsible for saving the events for Event Sourcing?

Instead of saving latest status of data into database, Event Sourcing pattern offers to save all events into database with sequential ordered of data events. This events database called event store. Instead of updating the status of a data record, it append each change to a sequential list of events.

Which database is best for Event Sourcing?

The core features such as guaranteed writes, concurrency model, granular stream and stream APIs make EventStoreDB the best choice for event-sourced systems - especially when compared with other database solutions originally built for other purposes, And on top of that, it's open source.


2 Answers

Your domain model is unaware of the storing mechanism. On the other hand it must make sure that the appropriate events will be published, no matter if you use an event store, a classical SQL store, or any other means of persistence.

If you rely on the event store to publish the events you'd have a tight coupling to the storage mechanism.

like image 126
Dennis Traub Avatar answered Oct 16 '22 16:10

Dennis Traub


Storing and publishing the event must an atomic instruction because if one of both actions fails, the listeners of this event will be out of sync with the producer of the event.

There is a another (more expensive) solution, compared to publishing the event from the event store, which is to use 2pc transactions (two-phases commit).

you can find some more intereting information here: https://cqrs.wordpress.com/documents/building-event-storage/

like image 37
Pierre-Jean Vardanéga Avatar answered Oct 16 '22 18:10

Pierre-Jean Vardanéga