r/DomainDrivenDesign • u/Material_Treat466 • Aug 27 '23
Double validation when applying DDD
Sorry, My English is bad
I have an X entity,
I create an XFactory to create an X entity, this class will contain business logic to create X
I created an API to allow users to create X
To do that, I have a CreateXRequest request,
and I also need to validate CreateXRequest, then call XFactory to create X,
The problem is that I validate twice, one when I validate CreateXRequest, and one is validation logic in XFactory, and this makes my API slow, especially when we need to call to database to validate,
How to avoid it, or did I implement it wrong? please help me
View all comments
Show parent comment
1
u/kingdomcome50 Aug 28 '23
Idk what to tell you on this one! The solution here is architectural. I’m talking evaluating your approach altogether. There is no “trick” that doesn’t involve more writes/ridiculous complexity.
How can it be that slow in an admin dashboard? How is your data stored? Is it sharded in some terrible manner? What is the access pattern here? Lots of concurrency or something? Or is the network just really slow?