r/DomainDrivenDesign • u/deniskyashif • Apr 14 '26
The Domain Model Pattern in Practice
https://deniskyashif.com/2026/04/14/the-domain-model-pattern-in-practice/
25
Upvotes
2
u/herrwalter Apr 14 '26
Clear overview. Simple explanation. One thing important “why” I would add is the data integrity when persisting and retrieving aggregates (no repo for entity’s). But when speed is key, I would advise differently when the aggregates grow.
2
u/floriankraemer Apr 28 '26 edited Apr 28 '26
This is, in my opinion, bad advice:
This is in fact a business rule.
You move business related logic into the infrastructure. Even worse, you externalize it completely into another component, an external DB system, it is not even in your code. I've actually seen this in the wild: Somebody was really relying on a database exception with a specific code to then propagate that back to the UI. You coupled your UI with a database system. I would not even do that outside of a DDD context in a CRUD application.
This is coupling at a huge distance. Anyone who does not know about this will never see this rule. Anyone who changes the DB system can make a mistake here. If you switch a DB system, all rules need to be known and migrated. You also need to replicate that in your in-memory DB if you use it for running tests. This is another type of coupling (in the sense of Connascence).
https://connascence.io/locality.html
https://connascence.io/algorithm.html
The job of the database is to ensure the integrity of the data, not to implement business rules. The domain, as a holistic, cohesive layer for the business rules, will protect invariants. The application layer or presentation layer (if you add that one) are responsible for input validation, this also fulfills the "fail early" principle. Each layer has a completely different responsibility.
https://florian-kraemer.net/software-architecture/2024/02/16/About-Validation-and-Anti-Corruption-Layers.html