渴望加载AR子实体的DDD性能问题 [英] DDD performance issue eager loading AR child entities

查看:85
本文介绍了渴望加载AR子实体的DDD性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天,我正在制作一个示例应用程序来申请/研究DDD。
DDD的原则之一(如果我错了,请纠正我)是,对实体的所有更改都应通过汇总根(AR)进行,并且应将其子实体加载到AR中。这样就更容易验证聚合一致性。
只有一个大细节困扰着我。我无法理解DDD如何处理性能问题。想象一下,我有一个Order(AR),例如,OrderLine为20000,30000。急于加载许多子记录会存在性能问题。用Order作为AR可以想象发生这种情况的另一种情况。
我期待着您的意见。

In the last days i'm making a sample application to apply/study DDD. One of the principles of DDD(Please correct me if I'm wrong) is that all the changes to an entity should be made through the Aggregate Root(AR) and an AR should be loaded with his child entities. In this way is eaiser to validate Aggregate consistency. There is only a little big detail that is bothering me. I'm not able to understand how DDD is dealing with performance issues. Imagine that i have an Order(AR) that have, let say, 20000, 30000 of OrderLine. Performance issues would exist eager loading a lot of child records. Saying Order as AR you can imagine another scenarios where this can happen. I'm looking forward to read you opinion about this subject.

推荐答案

DDD并不总是摆脱技术限制注意事项。如果您的AR可以包含大量子实体,请考虑是否可以使子实体自己拥有AR。在做出最终决定时必须考虑到最终的一致性。

DDD isn't always free from technical considerations. If you have an AR that can contain a very large number of child entities, consider if you can make the child entities ARs in their own right. This decision has to be made while taking eventual consistency into account.

在您提供的示例中,请考虑Order AR是否真的需要首先引用OrderLine实体以保持完整性。如果是这样,请考虑将OrderLine单独用作AR,在这种情况下,您可能必须处理最终的一致性。当然,如果使OrderLine成为AR,则应用程序逻辑将发生变化,因为需要在OrderLine上执行的操作将必须通过OrderLineRepository才能访问OrderLine,而不是通过Order AR。

In your provided example, consider whether the Order AR really needs to reference OrderLine entities in the first place in order to maintain integrity. If it does, consider making OrderLine an AR on its own, in which case you may have to deal with eventual consistency. Of course, if you make OrderLine an AR, you application logic will change, because an operations that need to be performed on the OrderLine will have to go through the OrderLineRepository to access the OrderLine instead of going through the Order AR.

有关此内容的更多信息,请查看有效的总体设计,作者是Vaughn Vernon

For more on this, check out Effective Aggregate Design by Vaughn Vernon.

这篇关于渴望加载AR子实体的DDD性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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