javamongodbcqrsevent-sourcingaxon

Axon framework - using separate Mongo collection of domain events for each aggregate root


We worry about performance of using single Mongo collection (domainevents) for domain events.

Is it good idea to split domainevents collection to separate collections for each aggregate root?

We have query model, that is generated based on events from multiple aggregate roots. If we split domainevents to multiple collections, will Axon still preserve the order of events across aggregate roots?

And is it generally good idea to do this?


Solution

  • There are a few questions here, that require different knowledge to answer. I am not a MongoDB expert, but do know my way around Axon, being the founder.

    The MongoEventStore in Axon doesn't natively support multiple collections for the domain events. So the answer to your order preservation query is: it won't work, unless you build support for it yourself. And then the order is guaranteed depending on how you built it.

    You can also consider sharding the Mongo Collection. Using the aggregate identifier as shard key will allow you to guarantee that queries for an aggregate stream hit a single shard. According to the documentation, it is recommended to avoid queries that do not include this shard key.

    The best approach to dealing with this performance issue, is to do a performance test. See how latency and throughput are affected as the size of the collection grows. Adding the right indexes may help.