In memory read model

39 views
Skip to first unread message

Lasse Lindgård

unread,
May 9, 2018, 5:40:24 AM5/9/18
to Axon Framework Users
For smaller applications, I'd really like to have my read model in memory. And have the state loaded by replaying the events.
And for even simpler cases I'd like to just query the aggregate.

I'll probably iterate away from those patterns as my application evolve, but they would be nice to use for proof of concepts and stuff like that.

I have only found examples on how to do JPA read models.

Can you point me to an example of how to build a read model, that is pure memory and replays when the ES aggregate a loaded?
Or how to query the actual aggregate?

milan...@axoniq.io

unread,
May 10, 2018, 5:08:57 AM5/10/18
to Axon Framework Users
Hi Lasse,

Let's tackle in-memory read models first. If you are building a CQRS application, read models are updated in event handlers as reaction to facts that something happened in the system (events are usually published during command processing). The way this models are persisted is up to the application developer - you can use in-memory databases, relational databases, NoSql databases, files, caches, or even Java data structures.

Querying the aggregates - this is something which does not comply with CQRS, but it can be achieved, as the matter a fact I was working on a project where we didn't have dedicated read models but were querying aggregates which were stored using JPA repositories. So, that's one way. 
On the other hand if your aggregates are event sourced, you could use EventSourcingRepository to load the aggregate state based on historic events. Of course, this queries can be only by Id and you cannot query based on the aggregate state.

Hope this helps you!

Cheers,
Milan.

jan.ga...@holisticon.de

unread,
May 15, 2018, 3:28:17 AM5/15/18
to Axon Framework Users
This is interesting, did not see this post before asking my "queryHandler on aggregate" question. Would this be an option to "read" from aggregates?

jan.ga...@holisticon.de

unread,
May 15, 2018, 3:43:04 AM5/15/18
to Axon Framework Users
Ah, forget it, typical "shower" idea ... on an aggregate I would only know this one aggregate of course ... so it's not able to answer queries ... I withdraw my question.
Reply all
Reply to author
Forward
0 new messages