I have a simple project that requires alot of reads and not many writes (once a day there are thousands of new registers per day, has hundreds of reads per minute, very little update to objects already present, a few per week), but I needed the application to be mindfull of past states of the model that the user is reading.
So if by any means a user makes a change to the object today, he must still be able to query the state of that object yesterday (necessary for analytical data to be precise).
This weekend I read on Event sourcing and created my own implementation with commands and events that were able to build from ground up the object and it mantained in the JPA repo the object and the events, and had a simple method for “reading old versions” which I simply give the timestamp or version number, and it would reload the events or an early snapshot and applies them until the model is in its desired version, then it would return it to the user, but the system is not very robust (I’ve made it in an afternoon) so I decided to try something more robust and with a proper community, already production proven. Axon got my attention instantly, but I cant find a way to do the replay for the view model with events (I already have a view model implemented by a projector, which updates the view model directly in the JPA repository), nor how could I rerurn a view model from scratch and rebuild my database (imagine someone commited a code which removed a very important EventHandler method from the projector and it simply made all view models of the last 12 hours unusables, how to I rerun it to rebuild my view models in the JPA to a usable state?)
To make queries that reflect states of the view model in time I am trying to implement it in a way in the view model, but this makes me think why should I even bother with event sourcing to build the state if I’m not going to use the power of the event sourcing to be able to do that?
Some of the things I’ve already tried are
- use the EventStore.load(“entity”, expectedVersion), without any result.
- Load an aggregate from a snapshot (I could not figure out how to do that)
I read in this forum that it should be possible to do something and receive an DomainEventStream to build a new aggregate, but I’d much prefer to separate the domain model from my view model, and since the view model is built using event handlers, how would I be able to rehidrate a new aggregate until the desired version of the domain model and then map it to my view model without breaking the sepparation betwen both (aka.: without placing query handlers inside the domain model?
One possible solution I see is to query directly the events and deserialize them, and use then in even another view model, this one being specificallt to rebuild objects given a list of ordered events, but again, since the framework already does something like this with the aggregate it makes me think that I’d be reinventing the well, and probably not even a round one!
If you have indication of example projects I could read would be great, I am very excited with Axon, and pondering if I should stick with 3.4 or go to 4.0 anyway, and I’ll use it in production, but I’d like to understand how to be able to do those things would help alot.