DDD: how to handle large collections

I am currently developing a backend for a social networking app in REST. I am very intrigued by the DDD principle. Now suppose I have a User object that has a collection of friends. It can be thousands if the application and the user become very successful. Each friend also has some properties, it is mainly a user. Looking at the DDD Cargo application example , a fully expanded Cargo object is stored and retrieved from CargoRepository from time to time. WOW, if there is a list in the placeholder, over time this will call OOM eventually. That's why there is a paginated dot and lazy loading if you approach the problem in terms of data. But how could you handle these large collections in a non-persistent DDD persistence?

+4
source share
3 answers

As pointed out in the comments of @JefClaes: you need to determine if your UserAR really requires a collection Friends.

Ownership does not necessarily mean that a fee is required.

Take the example of Order/ OrderLine. OrderLinedoesn't make sense without being a part Order. However Customer, to which a belongs Order, does not have a set of Orders. It may possibly have a collection ActiveOrdersif the customer is limited by the maximum number (or number) of active orders. Saving a collection of historical orders would be unnecessary.

, DDD. - Order , , , , , .

, / a Friend User AR.

-, , , . / , . .

, , Relationship AR.

+3

, .

, ,

  • , UserRepository GetUserWithFriends(int userId, int firstFriendNo, int lastFriendNo), . ..
  • , User instance _friends. , User , "" .
  • , UserRepository, . DDD.

DDD , , CRUD. DDD- .

+1

. , -.

​​:

friends
id, user_id1, user_id2

n-m. .

, , . , , . , , , . , .

Lazy-loading (AJAX), , , . , , - .

0

All Articles