I’d love to hear your opinion on how to implement projections. I’m using Axon 3 and EventSourcing with TrackingEventProcessor. My read-models live in a relational database.
When it comes to building up the read-model via projections, all is simple as long as the events contain all the data needed for the projection. But when a table in the read-model combines data from two or more aggregates things get more involved. This may occur when denormalizing for performance reasons, for instance.
In my research so far, I found two approaches.
Enrich events from aggregate A with data from aggregate B. The event-listener that does the projection then has all the data it needs and can simply execute an update/insert statement.
To get data that is not in the event, the projection (event-listener) needs to query tables of the read-model. And with that data and the data from the event it can execute the update/insert statement.
What I don’t like about approach A is that events containt data that is tied to the read-model. I would need to change the events when I change the read-model. This kind of coupling seems wrong to me.
What I don’t like about approach B is that it makes projections more complex. Also I think it requires the events to be projected strictly in order. Otherwise the queries against the read model could assume data that is not yet there. And maybe even fail due to missing records, or foreing key violations. Does Axon’s TrackingEventProcessor guarantuee that order of events?
Which approach would you use? Is there another, maybe better, one?
Thanks for your input!