Question

in CQRS, the event-sourcing is our only true source of information, never trust your read datamodel, then if I need to display a confirm messagebox which displays for example "user X's last 10 actions", then what approch should I use ?

1 - Send a command to query last 10 actions to my aggregates, then the aggregate publish 10 events which I handle in my UI containing the user's actions ?

2 - Or simply, query my Read model ?

what does CQRS say in my case ?

Thanks guys.

John SMITH

Was it helpful?

Solution

Never trust your read model not means that you need read data from write database. That means that your data in read model can become invalid. In this case you should make some fixes in your events handlers and because of you trust only write database rebuild read database from your events(write database).

Simple rules (at least i am follow these rules):

  1. Always read data from read database .
  2. You can access aggregate root only if you need verify something before apply event to AR and when you need replay events(within your domain should be only one method to access AR - GetById).

In your example everything is simple: handle user AR messages and store events in format (you should map data from event, not just store event) you need within user (nested collection in case of nosql database) or in separate table in case of sql database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top