I'm going to ask this question using a concrete example. An optimal answer would take into account that this is just an example for the general problem.
I'd like to implement a user management system with a Domain-Driven-DesignClean Architecture approach.
- My system has users and groups.
- Group objects contain users.
- Group objects have a
contains_userfunction. - users and groups are part of the same bounded context.
Question
How would I implement the contains_user function in Domain-Driven-DesignClean Architecture? How can I cleanly divide domain code / core and non-domain code / infrastructure?
More abstract:
How can I separate an implementation detail (RDS) from domain code without loosing performance?
My own thoughts
- Loading all users into the group might be bad performance-wise when there is a large number of users in a group.
- Performance-wise
contains_userwould best be implemented directly as DB query inside the function. But that would break DDDClean Architecture.