Domain design and Lazy loading

Hi Allard,
I am working in my third project with axon Framework, but right now I have a some doubts with a bit more complex domain

My domain look like Patient -> MedicalConditions->DailyEvaluations

Patient is my ‘main’ Aggregate, it contains name, address etc and some methods to update the information with @CommandHandler

Patient also contains a List of MedicalConditions, each MedicalCondition is an AbstractAnnotatedEntity, each patient can have 2 or 3 MedicalConditions, but each Medical Condition need DailyEvaluation (another AbstractAnnotatedEntity) and stored as collection List with the medical Condition, I figure on that in a year the main Patient aggregate can grow caused by the daily evaluation…

My question is very simple, if I going o update only the address information of a patient, when AxonFramework execute the commandhandler also load the entire set of MedicalConditions and DailyEvaluations? If yes there is a way to deal with that?

Thanks
Danilo

Hi Danilo,

I suppose you’re event sourcing? In that case, Axon wouldn’t be able to know what part of the model needs to be event sourced. Sourcing an extra part of the model would involve re-iterating over all past events, which is much more expensive than setting up the entire aggregate in the first place. Furthermore, do you really need all the conditions and evaluations in that model? Often, you really only need a small part of it, as the only responsibility of the command model is to process commands. Fine-grained details aren’t always necessary to do that. Ask yourself this question: does the outcome of any of my commands depend on a DailyEvaluation that was created a year ago?

Cheers,

Allard

Hi Allard,

Yes we are using event sourcing. In this case we want to keep the main aggregate Patient and their Value Objects Conditions/DailyEvaluations together, because there are some dependencies between them, by example, if the user add a Weight, we need recalculate the Patient BMI (BMI depend of the last weight and height of the patient), if the BMI value is below of a value and the Patient has Diabetes as medical condition, we need to put yellow light alert to the Member class, also we need the history, because in the case that the BMI value fell below a value for 3rd time along the last year, we need to put a red alter, to the Patient Aggregate.

A second alternative is to separate and create a new Aggregate Condition/DailyEvaluations and using Saga to communicate with the Patient Aggregate.

Thanks.

Hi Danilo,

let’s take this as an example: “also we need the history, because in the case that the BMI value fell below a value for 3rd time along the last year, we need to […]”
In this case, you don’t need the entire history. All you need to do keep count of the number of times the BMI fell below a threshold within the last year. That’s just an int. It doesn’t need to be a List of “DailyEvaluation” instances.

Cheers,

Allard