如何设计 MongoDB 数据模型来存储 Event Sourcing 事件

How to design MongoDB data model to store Event Sourcing events

如果我为每个 aggregate type 创建一个 table(或 document databases 中的 document),我可以在重构 [=15] 时合并数据库或对它们进行分片=] 端的 microservices,结果应用程序变得更具可扩展性,同时也提高了加载速度 events

在设计这样的 event store 时,我应该注意什么副作用吗?

编辑:

我目前正在使用 MongoDb

如果我为每个 aggregate id 创建一个 collection 会怎么样? 或者 database 每个 aggregate type,和 collection 每个 aggregate id ...?

这在性能、数据管理的便利性、可维护性或进一步的可扩展性方面是否存在问题?

If I create a single table (or document in document databases),I can merge databases or shard them whenever I refactor the write microservices, and as the result the application becomes more scalable.

Are there any side effects I should be aware of while I'm designing the event store like that?

我还没有看到任何关于该设计的权威讨论。

事件溯源社区中曾讨论过为每个 类型 聚合设置一个单独的 table。您可以找到该讨论 here。执行摘要:更有经验的从业者似乎对任何人故意这样做感到震惊。

您应该记住的一件事是,虽然事件是真实的(它们描述了业务感兴趣的东西),但聚合是人为的。如果重新设计聚合边界需要您将事件到处移动,您可能会不高兴。

以下内容可能会有帮助