您如何处理CQRS中的外键读取侧故障? [英] How do you handle foreign-keys read-side failures in CQRS?

查看:82
本文介绍了您如何处理CQRS中的外键读取侧故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL数据模型中有表A和表B,表A具有指向表B的外键。现在,您要将CRUD体系结构迁移到CQRS。想象以下情况:

You have table A and table B in your SQL data model, with table A having a foreign key towards table B. You now want to migrate your CRUD architecture to CQRS. Imagine the following scenario:


  • 您收到一条命令以保留A的新条目

  • 您写入您的附加日志并对其进行处理,以更新您的状态

  • 读取端将其拾取并未能插入数据库中

在这种情况下,您的写端和读端将永远无法达到一致性。您如何处理CQRS中的读取侧约束?

In this situation, your write side and read side will never reach consistency. How do you handle read-side constraints in CQRS? Should validation occurs in the write side instead?

推荐答案

我相信您可以从中得到一些启发:

I believe you can get some inspiration from this:

如何处理基于集合的方法CQRS中的一致性验证?

它的简称是,新的A聚合需要由另一个聚合创建,比如C(创建者)。在这种情况下,C保留了所有A的ID的列表,因此可以在聚合级别而不是视图模型上进行检查。

The short of it is, the new A aggregate needs to be created by another aggregate, let's say C (creator). In this case C holds a list of all A's IDs, so that the check can be done at the aggregate level instead of the view model.

如果您的问题更为笼统然后问如何处理视图模型更新失败,这实际上取决于。可能是设计问题(例如错误的事件顺序,缺少先决条件或不变的检查),错误或其他。我通常要做的是,如果没有自动补救措施,我将这些实体锁定并发送到需要手动干预的实体列表中。

If your question is more generic and you ask "how do you handle view model update failures", then it really depends. It could be a design issue (e.g. incorrect sequence of events, lack of pre-conditions or invariant checks), a bug, or else. What I normally do is that I lock those entities and send them to a list of entities requiring manual intervention, if there is no automatic remedial.

这篇关于您如何处理CQRS中的外键读取侧故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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