read model side of Vaughn Vernon's cqrs+es

447 Views Asked by At

The lokad-iddd-sample code implements the cqrs+es write side discussed in Vaughn Vernon's book. Unfortunately, the read model side is incomplete. Is anyone aware of similar code (ideally based on Vaughn Vernon's book) which implements a working version of the read model side?

1

There are 1 best solutions below

0
On BEST ANSWER

The problem is that almost all open-sourced code-bases which use cqrs+es are either based on hopelessly trivial examples. Therefore they only show the basics, and deprive you of showing good examples of complex situations. Making them, imo, useless for all but getting a feel for the concepts.

So getting a "working version" as an example, depends on how you define that. If your looking for simple stuff, there are loads of examples of OSS project that have an "working example" of a readmodel. Just use google.

Implementing a readmodel is arguably the simplest aspect of ES/CQRS. When combined with an ES, your aggregateroot emits events, and you subscribe to those events.

Consuming those events allows you to build your readmodel, one small piece at a time. How your readmodel is defined in terms of enitities is up to you. There is no right or wrong here. It all depends on what kind of problem your looking to solve.

For example: When recieving an OrganisationCreated event, do I create a singular organisationEntity i can directly retrieve? Sure, if you have detail views that require such an representation, why not.

But then, do you besides that singular entity, keep a seperate list entity containing all known organisations, or will simply execute a query (select * from, if you will) over the organisationEntity and build my result like that? Once again, that all depends on your requirements.

And the best part of using ES is that you can change your readmodel, or simply introduce new entities without much problems. You can always rebuild your readmodel from your ES.