Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQRS / communication between contexts / eventstore / push or pull?

Communications between bounded context in CQRS/ES architecture is achieved through events; context A generates events as response to commands, and these events is then forwarded to context B through event bus (message queue).

Or... you can store the events in eventstore (that belongs to context A). Or... both (store and forward).

My question is: from context B, should I pull the events from the context store? or simply consume the events pushed through the event bus?

I'm leaning toward the pulling approach. Because then we can do some catching up in context B. In contrast, in the push approach, context B might be unaware of events that were delivered while B is experiencing downtime.

So... does it mean... when we have eventstore, we can simply forget about the message queue (seems redundant)?

Or am I missing something here?

like image 826
Cokorda Raka Avatar asked Sep 09 '16 20:09

Cokorda Raka


1 Answers

You'll want to review Consume event stream without Pub/Sub

At the DDD Europe conference, I realized that the speakers I talked with where (sic) avoiding Pub/Sub whenever possible.

The discussion that follows may have value. TL;DR: not many fans of pub/sub there.

Konrad Garus on Push or Pull?, describing the Pull design:

In the latter (and simpler) design, they only spread the information that a new event has been saved, along with its sequential ID (so that all projections can estimate how much behind they are). When awakened, the executor can continue along its normal path, starting with querying the event store.

Why? Because handling events coming from a single source is easier, but more importantly because a DB-backed event store trivially guarantees ordering and has no issues with lost or duplicate messages. Querying the database is very fast, given that we’re reading a single table sequentially by primary key, and most of the time the data is in RAM cache anyway. The bottleneck is in the projection thread updating its read model database.

In the large, it comes down to this: when people are thinking about event sourcing, they are really thinking about histories, rather than events in isolation. If what you really want is an ordered sequence of events with no gaps, querying the authority for that sequence is much better than trying to reconstruct if from a bunch of disjoint event messages.

But - once you decide to do that, then suddenly the history, and all of the events that appear within it, becomes part of the api of context A. What happens when team A decides that a different event store implementation is more suitable? Can they just roll out a new version of their own services, or do we need a grand outage because every consumer also has to get updated?

Similarly, what happens if we decide to refactor context A into context C and context D? Again, do we have to screw around in context B to get the data we need?

Maybe the real problem is that context B is coupled to the histories in context A, and those histories should really be private? Should context B be accessing context A's data, or should it instead be delegating that work to context A's capabilities?

Udi Dahan essays on SOA may jump start your thinking in that direction.

like image 166
VoiceOfUnreason Avatar answered Oct 07 '22 07:10

VoiceOfUnreason