重播事件以进行调整 [英] Replay events for adjustments

查看:98
本文介绍了重播事件以进行调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设地,我正在使用一个使用事件采购"(存储业务事件)进行物料买卖的系统;有时会生成一份报告,其中包含价格和成本信息.

Hypothetically I'm working on a system that uses "Event Sourcing" (storing the business events) that has purchase and selling of materials; at some point a report, with prices and costs information is generated.

想象一下,我的一位客户打电话给我说:成本错了,对我来说,利润规则就是这种方式."

Imagine that one of my clients call me and says, "The costs are wrong, for me, the rules from profit are this way".

我可以添加更多处理程序或更改规则以适应这种特殊情况,然后重播事件.

I could add more handlers or change the rules to adjust to this particular case, and replay the events.

但是我的问题是,这是正确的方法(或者至少是更好的方法)?

But my question is, this is the correct approach (or at least the better)?

推荐答案

在事件源系统中,事件是不可变的-发生了什么的简单事实.重写事件的历史是一件根本不做的事情[1].

In an event sourced system, the events are immutable - the simple facts of what has happened. Rewriting the history of the events is a thing one simply does not do[1].

更改基于这些事件得出结果的计算逻辑绝对是一件正常的事情(这是即使采购也能实现的关键任务之一).

Changing the calculation logic that derives a result based on these events is absolutely a normal thing to do (it's one of the key things even sourcing enables).

您是真正更改代码还是提供替代算法是一个选择的问题-如果原始代码实际上是一个bug(听起来像您的情况),请更改代码.如果没有,写一个新的.

Whether you actually change your code or provide an alternate algorithm alongside is a matter of choice - if the original was effectively a bug (sounds like your case), change the code. If not, write a new one.

在某些情况下(通常不建议这样做),总是可以处理原始事件中的所有内容;如果是这样,您要做的就是更改推导逻辑,然后就完成了.

In certain cases (not generally advised), one always works everything from the original events; if that's the case, all you have to do is change your derivation logic and you're done.

如果您已将事件投影并已非规范化到持久性存储中,并且已确定情况代表错误,则通常的方法是:

In the case where you've projected the events and denormalised into a persistent store, and have decided that the situation represents a bug, the normal approach is to:

  1. 吹走现有的非规范化状态
  2. 重播事件以产生预期的替代派生

请注意,只有当您拥有一个非临时的非规范化状态存储区(该存储区保留了现在被取代的基础上计算出的值)时,此功能才起作用. (将非规范化状态投影到内存中是完全正确的;在这种情况下,吹走"更为简单.)

Note that this only comes into play if you have a non-ephemeral denormalised state store that retains values calculated on the basis now being superseded. (It's perfectly valid to project the denormalised state into an in-memory stash; in such a case the 'blowing away' is simpler).

另一种情况是您已经实现了快照优化-在这种情况下,也将重新投影以进行不同的非规范化.

Another scenario is where you've implemented snapshotting optimisations - in that case one would also re-project to denormalise differently.

[1]是的,在某些特殊情况下可以证明其合理性,但这是.001%的情况

[1] Yes there are exotic cases where it can be justified but that's a .001% case

这篇关于重播事件以进行调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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