命令查询责任分离(CQRS)/事件溯源(ES):为什么要使用它?如何解决一致性问题?

Command Query Responsibility Segregation (CQRS) / Event Sourcing (ES): Why use it? How to address consistency issues?

几个月前,我第一次听说 CQRS/ES 是在 ScalaDays San Francisco 的演讲中。从那时起,我注意到技术写作中偶尔会提到这些术语,最近一次是 Fiverr's blog post on the topic

到目前为止看起来很有趣,但我遇到了一些相关问题,我想知道是否有共同的解决方案:

此外,采用这种模式有哪些优势,它们如何超过额外复杂层的成本?

提前致谢!

  • How do you deal with eventual consistency and potentially inconsistent views in the short term?

  • How do you deal with use cases where the user interface requires an immediate result to the request?

一个常见的误解是使用事件溯源自动意味着最终一致的读取模型。许多 ES 从业者(包括 Udi Dahan 和 Greg Young)建议从同步、立即一致的模型开始,并仅在需要时才转向最终一致性。

  • How do you deal with business logic which touches multiple resources a.k.a. atomic reads/writes a.k.a. transactions?

这是一个没有单一答案的复杂问题,可能更适合讨论论坛而不是像 SO 这样的 Q/A 论坛。我建议在 DDD/CQRS discussion group.

中四处查看(并发布)

此外,这里有一些我最近找到的关于该主题的幻灯片。他们涵盖了更多 "why"/"why not" 方面,来自一个在实践中使用 CQRS/ES 的团队。

http://ookami86.github.io/event-sourcing-in-practice/