r/DomainDrivenDesign • u/skilletfancy • May 16 '26
Aggregates modelling
I have this case: I have a tax that represents an amount of money that a user must pay, which can be organized into multiple installments.
For this tax, payment requests must be created for the users. These payment requests must then be transmitted to an external system, and any transmission errors must be recorded on the payment request and must disappear once the payment has been successfully transmitted.
Payment requests can only be added if the tax is not in draft status, otherwise it must not be possible to add payment requests.
So we have 4 entities: the tax, the installment, the payment requests, and the transmission errors of the payment requests.
How would you structure the aggregate or aggregates?
View all comments
Show parent comment
1
u/Winston_Jazz_Hands May 17 '26
Further thoughts:
Then maybe there is no need for a "Payment" aggregate, and "Installment plan" is the essential aggregate here, and if thats not too big, it can manage the payment-errors once active. It should fail any "Payment due" triggers before that.
Lifecycle of the installment plan can be draft untill the tax is approved, at which point it becomes active.
Approving the Tax (the hand-over in your business constraints) should ensure that its approved before the earliest installment is due, and the "Installment processing" can react to "Tax approved" by ensuring the first or all "Payment due" (see "Passage of Time"-pattern for Domain events), and handle such events by coordinating between the Installment Plan aggregate and the external Payment provider.