I am implementing Domain-Driven Design (DDD) and facing a problem: balancing database performance with clean domain modeling.
I want to stop loading child entities that I don't need when getting an Aggregate Root from the database. I don't just mean huge lists of items. I also mean small child entities that are simply not used in the current business action.
What I've considered: I could use Lazy Loading, but this usually makes the domain model depend heavily on the ORM. This mixes the domain model and data model, breaking the rule that the domain shouldn't care about the database.
My questions are:
How to load only what I need? Are there good patterns to run business logic on an Aggregate Root without loading the whole object tree, while still keeping the business rules safe?
Using ORM entities as Domain Models: Is it a common and acceptable trade-off to just use ORM entities directly as the Domain Model? This makes Lazy Loading easy, but is the performance boost worth breaking the clean domain design?
Balancing performance and DDD: I really like the clear business logic that DDD brings, so I don't want to drop it for a simple database-first approach. How do experienced developers balance making fast database queries with keeping the Domain Model clean and separate?
Any advice or real-world patterns would be great. Thanks!