Apologies in advance, I have tried to find the answers to these questions but haven’t succeeded so decided to ask them here…
I’m currently in the process of evaluating CQRS as a pattern, and Axon Framework as a framework to support that.
I have managed to put together a working example based on snippets of code from around the web using MongoDB as the event store so have a reasonable idea what is going on.
The specific questions are more related to best practice and wondered if anyone could give me some advice:
Q1. A lot of sample code I have seen spends a lot of time handling the commands and generating/handling events, but seems to skip over the read side of the pattern.
What is the best practice for building a read-model that queries can operate against?
Is it to use tables in an RDBMS to denormalise the aggregate into a form that is applicable to the readers?
If I update an RDBMS table in the event handler (annotated with @EventSourcingHandler) what happens if the event or write to the RDBMS fails? How do I best handle that?
Q2. When I execute a command the aggregate is rebuilt from all of the domain events to-date. If I have an update of the RDBMS read model in each event handler as well (based on the question above) it will be doing lots of potentially un-necessary inserts/updates.
Is that just a side-effect of the pattern that this needs to happen, because the aggregate is always built from prior domain events first?
I understand that if you need to recreate the read-model from the stored domain events then that’s all needed, but for just applying just one more event seems overkill.
Is snapshotting the best way around this (so that the read-model is recreated with less events)?