问题描述
我想要设置一个小事件源lib。
我在线阅读了几个教程,一切都到此为止。
唯一的问题是,在这个不同的教程中,有两种不同的数据库策略,任何评论为什么他们使用他们使用的一个。
所以,我想问你的意见。
重要的是,为什么你更喜欢你选择的解决方案。
-
解决方案是db结构,
- 解决方案是db结构,其中只创建一个通用表,并将事件作为序列化字符串保存到一个列。
在这两种情况下,我不知道他们如何处理事件更改,也许他们创建了一个新的。
感谢
我建立了自己的事件源lib, 2这里是为什么。
- 您按汇总ID而非事件类型查询事件流。
- 按顺序重播事件如果他们都在不同的表
- 这将使升级事件有点疼痛
有一个说法,你可以存储每个聚合的事件,但这取决于项目的要求。
我有一些关于如何使用您可能会发现有用的事件流。
我希望您觉得有用。
I want to setup an small event sourcing lib.I read a few tutorials online, everything understood so far.
The only problem is, in this different tutorials, there are two different database strategies, but without any comments why they use the one they use.
So, I want to ask for your opinion.And important, why you would prefer the solution you choose.
Solution is the db structure where you create one table for each event.
Solution is the db structure where you create only one generic table, and save the events as serialized string to one column.
In both cases I'm not sure how they handle event changes, maybe they create a hole new one.
Kind regards
I built my own event sourcing lib and I opted for option 2 and here's why.
- You query the event stream by aggregate id not event type.
- Reproducing the events in order would be a pain if they are all in different tables
- It would make upgrading events a bit of pain
There is an argument to say you can store events on a per aggregate but that depends of the requirements of the project.
I do have some posts about how event streams are used that you may find helpful.
6 Code Smells With Your CQRS Events and How to Avoid Them
Aggregate Root – How to Build One for CQRS and Event Sourcing
How to Upgrade CQRS Events Without Busting Your Event Stream
I hope you find that useful.
这篇关于最佳事件采购数据库策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!