强制聚合之间不变的最佳方法? [英] Best way to enforce invariants between aggregates?

查看:95
本文介绍了强制聚合之间不变的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理聚合之间一致性的最佳方法是什么?以Vaugn Vernon的书为例,您拥有BacklogItem聚合和SprintAggregate。引发BacklogItemEvent时,事件处理程序将其捕获并尝试更新Sprint Aggregate。如果该操作失败怎么办?如何找到处理这种情况的最佳方法?据我了解,有3种选择:
1)在一次交易中更新所有聚合。我们失去了可伸缩性,但获得了一致性。
2)什么也不做。只需记录和错误并等待手动干预。
3)使用佐贺。这使设计变得复杂,并迫使我们实现每个用例,而这些用例必须在单独的对象(传奇)中的集合之间建立变量。如果Sprint更新失败,则saga将尝试取消提交待办事项(补偿)。
您将选择哪个选项,以及基于什么条件?

What is the best way to handle consistency between aggregates? Having an example from Vaugn Vernon book, you have BacklogItem aggregate and SprintAggregate. When BacklogItemEvent is raised the event handler catches it and tries to update Sprint Aggregate. What if this operation fails? How to find the best way of handling this situation? As far as I understand there are 3 options: 1) Update all aggregates in one transaction. We loose scalability, but we gain consistency. 2) Do nothing. Just log and Error and wait for manual intervention. 3) Use saga. This complicates the design and forces us to implement each usecase which has to enforse envariants between aggregates in a separate object(saga). If Sprint update fails, saga will try to Uncommit Backlog item (compensate). Which of this option will you choose, and what is the criteria you base on?

推荐答案


处理聚合之间一致性的最佳方法是什么?

What is the best way to handle consistency between aggregates?

如果正确设计了聚合,则随着时间的推移,您将处理聚合之间的一致性(aka:最终一致性)。

If your aggregates are correctly designed, then you handle "consistency" between aggregates over time (aka: eventual consistency).


如果此操作失败怎么办?

What if this operation fails?

仔细阅读种族条件不存在;乌迪·达汉(Udi Dahan)提出了这样一个论点,即协作域中的操作应该失败。

Take a careful read through Race Conditions Don't Exist; Udi Dahan makes an argument that operations in collaborative domains should not fail.


在一次交易中更新所有聚合。

Update all aggregates in one transaction.

您可以做到;但这实际上意味着这两个实体实际上是单个隐式集合的一部分。换句话说,它强烈建议您没有正确的集合边界。

You can do that; but what that effectively means that that the two entities are really part of a single implicit aggregate. In other words, it strongly suggests that you haven't got your aggregate boundaries in the right place.

尝试在单个交易中修改多个集合实际上是有效的。 >两阶段提交,并因此而引起所有其他复杂情况。

Trying to modify a multiple aggregates in a single transaction is effectively two phase commit, with all of the additional complications that arise from that.


什么都不做。只需记录并出错,然后等待手动干预。

Do nothing. Just log and Error and wait for manual intervention.

是的;看,例如;格雷格·杨(Greg Young)关于仓库系统和异常报告怎么说。

Yup; see, for instance; what Greg Young has to say about warehouse systems and exception reports.


使用传奇。这使设计复杂化,并迫使我们实施每个用例,每个用例都必须在单独的对象(传奇)中强制汇总之间的不变量。

Use saga. This complicates the design and forces us to implement each use case which has to enforce invariants between aggregates in a separate object(saga).

这些天,通常会看到流程管理器而不是传奇,它具有更具体的含义。但是,是的,如果域模型需要在聚合之间进行编排,那么您将需要在某个地方描述编排逻辑。

These days, you'll normally see "process manager" rather than "saga", which has a more specific meaning. But yes, if the domain model needs orchestration between aggregates, then you are going to need to describe the orchestration logic somewhere.

您可能想回顾Rinat Abdullin对< a href = https://abdullin.com/post/ddd-evolving-business-processes-a-la-lokad/ rel = nofollow noreferrer>正在发展的业务流程;他提出了一个很好的论据,即自动化只是复制操作员将要执行的动作。

You might want to review Rinat Abdullin's discussion of Evolving Business Processes; he makes a pretty good argument that the automation is just replicating the actions the human operator would take.


您会选择哪个选项,以及您所依据的标准是什么?

Which of this option will you choose, and what is the criteria you base on?

我非常喜欢简单到容易。因此,我将针对异常报告,其论点是:(a)这些失败无论如何都应该很少发生,因此我们不想在远离幸福之路的工作上投入大量的设计资金,(b)如果我们系统中有失败的命令,那么我们应该有一个机制来报告失败的命令 ,所以我只是在利用已经存在的命令。

I strongly prefer simple to easy. So I would aim for exception reporting, on the argument that (a) these failures should be rare anyway, so we don't want to be investing a lot of design capital in work far off the happy path, and (b) if we have failing commands in the system, then we ought to have a mechanic for reporting failed commands anyway, so I'm just leveraging what's already present.

如果时间紧迫,如果项目尚未取得足够的成功以至无法扩展,如果我手头没有所需的报告,那么我可能宁愿将更改潜入单个事务中,然后在开发过程中提出异常报告,以提请大家注意以后需要做更多的工作。

If I were squeezed for time, if the project hadn't yet become successful enough to need to scale, if I didn't have the reporting pieces needed at hand, I might prefer instead to sneak the changes into a single transaction, and then raise an exception report in the development process itself to call attention to the fact that more work needed to be done later.

这篇关于强制聚合之间不变的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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