I hope you can help me with the design of a data ingestion process.
Currently, I have an existing aggregate called ExperiencePricing
and an existing command called SetExperiencePricingCommand
. The aggregate represents the price of a tour over a list of periods.
A business request has asked me to support the upload of a CSV file to simultaneously set the prices of different tours.
The immediate idea is to process the M rows of the file and generate N (N < M) SetExperiencePricingCommands
to be launched one by one in a fire-and-forget manner.
One of the main requirements is to provide feedback to the user. If there are errors, they should be displayed, and the operation should continue until the entire file is validated. The user will need to fix any errors and create another request. Obviously, the result (partial or final of the process) must be saved so that it can be viewed in the future as well.
Each Record has 3 pieces of information – Value Objects (TargetTour, TargetPrice, TargetPeriod), and
the flow that could lead me to the construction of the command is as follows:
File –> Parsing –> Merging –> Processing –> Validation
Parsing create Value Objects and basic invariants
(e.g., type compliance, price > 0, startDate < endDate)
Merging collapse records
I can generate an entity ensuring the following invariant:
if (A.TargetTour == B.TargetTour && A.TargetPrice == B.TargetPrice && A.TargetPeriod.Overlaps(B.TargetPeriod))
then new C(A.TargetProduct, A.TargetPrice, Merge(A.TargetPeriod, B.TargetPeriod))
Processing: Business rule application
-
Business rule application
if (A.TargetTour == B.TargetTour && A.TargetPrice != B.TargetPrice && A.TargetPeriod.Overlaps(B.TargetPeriod) ) then the price to apply during the overlapping period is that of A if A.TargetPeriod.Days < B.TargetPeriod.Days B if A.TargetPeriod.Days > B.TargetPeriod.Days C Fail
The output will be an Entity of type (TargetTour, TargetPrice, List)
- Hidrate (fetch default values from Tour configuration and so on)
Validation:
TourExistencePolicy: Tour exists on database
TargetPeriodsPolicy each period in List is inside a List of RunningPeriods defined for the Tour
After validation, a summary is provided to the user, and the set of commands should only be launched after confirmation.
My difficulty lies in modeling this process in DDD since there are different invariants at different stages. Some invariants apply to the individual record, some to a grouping of records, and others to a different grouping.
Does it make sense to create an aggregate for each phase of the process?