Domain Modeling with Event Sourcing

Hi, all

Recently I’m trying to develop a payment service with Axon Framework, but I’m a little bit confused when it comes to domain modelling.

The service has a simple one-to-many relationship: merchant -> transactions, so I have three options to model them in my mind so far:

  1. a single root aggregater - merchant, and clearly this way has a high write ratio because a merchant won’t change a lot once created but transactions will keep coming;
  2. two root aggregaters: one for merchant, one for transaction. Personally speaking I prefer this way than others, but the creation of transaction requires some data from merchant, so either it comes from an extra read-only data source or the merchant aggregater which can be tricky because a version number must be specified for EventSourcingRepository to load the correct merchant;
  3. using saga, but it seems to overkill for such simple requirement…
    I’m not so familiar with CQRS and Axon Framework as well, so any suggestion is welcome, thanks.


Actually EventSourcingRepository can retrieve an aggregrate by id only, my fault…

Hi Nick,

Aggregates are not for querying, so whatever you choose, do not load a Merchant aggregate from the event store to query its state.

If you go for option B it’s best to pass the required merchant data with the command to the transaction aggregate. The merchant data you need can be obtained from your query model of the merchant. Your query model is not the same as your merchant aggregate. It is typically a basic JPA entity that was created and updated in reaction to events published by the aggregate.

Hope that helped.


Hi, Rene

Yes, I agreed with you aggregate should NOT used for querying data, thank you for such a great suggestion.

I guess I’ll stick to plan B and maybe saga later if necessary :smiley: