I am aware there is a lot of topics on set validation and i won’t say i have read every single one of them but i’ve read a lot and still don’t feel i’ve seen some definite answer that doesn’t smell hackish.
Consider this:
- we have a concept of
Customer
Customer
has some general details dataCustomer
can makeTransaction
(buying things from the store)- if
Customer
is in credit mode then he has a limit of how much he can spend in a year - number of
Transactions
perCustomer
per year can be huge (thousands+) - it is critical that
Customer
never spents a cent over a limit (there is no human delivering goods that would check limit manually) Customer
can either create newTransaction
or add items to existing ones and for both the limit must be checkedCustomer
can actualy be aCompany
behind which there are manyUsers
making actual transactions meaningTransactions
can be created/updated concurrently
Obviously, i want to avoid loading all Transactions
for Customer
when creating new or editing existing Transaction
as it doesn’t scale well for huge number of Transactions
.
If i introduce aggregate dedicated to check currentLimitSpent
before create/update Transaction
then i have non-transactional create/update (one step to check currentLimitSpent
and then another for create/update Transaction
).
I know how to implement this if i don’t care about all ddd rules (or if its eventual consistency approach) but i am wondering if there is some idiomatic ddd way of solving this kinds of problems with strict consistency that doesnt involve loading all Transactions
for every Transaction
create/update?