DDD:如何处理大型馆藏 [英] DDD: How to handle large collections

查看:77
本文介绍了DDD:如何处理大型馆藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为REST中与社交网络相关的应用程序设计后端。我对DDD原理很感兴趣。现在,假设我有一个User对象,该对象具有一个Friends Collection。如果应用程序和用户将变得非常成功,则这些数字可能为数千。每个朋友也将具有一些属性,它基本上是一个用户。
查看 DDD Cargo应用示例,它是完全扩展的Cargo -对象会不时地从CargoRepository中存储和检索。哇,如果聚合根目录中有一个列表,随着时间的流逝,这最终将触发OOM。这就是为什么如果您从以数据为中心的角度来解决问题,则会出现分页和延迟加载的原因。但是,如何在持久性未知的DDD中处理这些大集合呢?

I'm currently designing a backend for a social networking-related application in REST. I'm very intrigued by the DDD principle. Now let's assume I have a User object who has a Collection of Friends. These can be thousands if the app and the user would become very successful. Every Friend would have some properties as well, it is basically a User. Looking at the DDD Cargo application example, the fully expanded Cargo-object is stored and retrieved from the CargoRepository from time to time. WOW, if there is a list in the aggregate-root, over time this would trigger a OOM eventually. This is why there is pagination, and lazy-loading if you approach the problem from a data-centric point of view. But how could you cope with these large collections in a persistence-unaware DDD?

推荐答案

正如评论中提到的@JefClaes:需要确定您的用户 AR是否确实需要 Friends 的集合。

As @JefClaes mentioned in the comments: You need to determine whether your User AR indeed requires a collection of Friends.

所有权并不一定意味着需要收集。

Ownership does not necessarily imply that a collection is necessary.

接受订单 / OrderLine 示例。 OrderLine 没有成为 Order 的一部分 就没有任何意义。但是,订单所属的客户没有订单的集合。如果将客户限制为最大数量(或数量)的iro活动订单,则它可能具有 ActiveOrders 的集合。

Take an Order / OrderLine example. An OrderLine has no meaning without being part of an Order. However, the Customer that an Order belongs to does not have a collection of Orders. It may, possibly, have a collection of ActiveOrders if a customer is limited to a maximum number (or amount) iro active orders. Keeping a collection of historical orders would be unnecessary.

我怀疑大量的收集问题不仅限于DDD。如果要接收包含成千上万行的 Order ,则可能会在设计上进行取舍,但是该订单很可能会被简单地拆分成较小的订单。

I suspect the large collection problem is not limited to DDD. If one were to receive an Order with many thousands of lines there may be design trade-offs but the order may much more likely be simply split into smaller orders.

在您的情况下,我断言包含/排除 Friend 与<$的一致性没有多大关系。 c $ c> User AR。

In your case I would assert that the inclusion / exclusion of a Friend has very little to do with the consistency of the User AR.

要记住的一点是,一旦开始使用域模型来查询开始运行陷入各种奇怪的问题。因此,请始终尝试使用具有简单查询接口的某些读/查询模型来思考,该接口可以直接访问数据而无需使用域模型。这样可以简化事情。

Something to keep in mind is that as soon as you start using you domain model for querying your start running into weird sorts of problems. So always try to think in terms of some read/query model with a simple query interface that can access your data directly without using your domain model. This may simplify things.

因此,也许关系 AR可以在这方面提供帮助。

So perhaps a Relationship AR may assist in this regard.

这篇关于DDD:如何处理大型馆藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆