AWS 事件溯源实施

AWS Event-Sourcing implementation

我是微服务和事件溯源方面的新手,我正试图找出一种在 AWS 上部署整个系统的方法。

据我所知有两种实现事件驱动架构的方法:

所以我的基本策略是将每个命令转换为存储在 DynamoDB 中的事件,并利用 DynamoDB Streams 将新事件通知其他微服务。但是怎么办?我应该使用前两个解决方案中的哪个?

第一个有以下优点:

但是缺点比较有问题:

第二个具有以下优点:

缺点:

非常感谢各种建议!

I'm quite a newbe in microservices and Event-Sourcing

回顾 Greg Young 的演讲 Polygot Data 以更深入地了解接下来的内容。

跨服务边界共享事件有两种基本方法 - 推模型和拉模型。对于关心事件顺序的订阅者,拉式模型维护起来“更简单”。

基本思想是每个订阅者跟踪自己的高水位线以了解它处理的流中的事件数量,并查询事件列表的有序表示以获取更新。

在 AWS 中,您通常会通过查询更新事件列表的权威服务(其实现可能包括分页)来获得此表示。该服务可能会通过直接查询 dynamodb 或通过从 DynamoDB 获取最新密钥,然后在 S3 中查找事件的缓存表示来提供事件列表。

在这种方法中,被推出系统的“事件”实际上只是通知,允许订阅者减少写入 Dynamo 和他们的请求之间的延迟自己阅读。

我通常会使用 SNS(扇出)来广播通知。需要对他们处理过的通知进行簿记支持的消费者可以使用 SQS。但传达有序事件的主要渠道是拉动。

我自己并没有仔细研究 Kinesis - 有一些 general discussion in earlier questions - 但我认为 Kevin Sookocheff 在写作时正在做一些事情

...if you dig a little deeper you will find that Kinesis is well suited for a very particular use case, and if your application doesn’t fit this use case, Kinesis may be a lot more trouble than it’s worth.

Kinesis’ primary use case is collecting, storing and processing real-time continuous data streams. Data streams are data that are generated continuously by thousands of data sources, which typically send in the data records simultaneously, and in small sizes (order of Kilobytes).

Another thing: the fact that I'm accessing data from another 
microservice stream is an anti-pattern, isn't it?

嗯,将系统划分为微服务的部分目的是为了减少系统功能之间的耦合。跨微服务边界访问数据会增加耦合。所以那里有些紧张。

But basically if I'm using a pull model I need to read 
data from other microservices' stream. Is it avoidable?

如果您查询所需信息的服务,而不是自己将其从流中挖掘出来,则可以减少耦合——这很像向服务请求数据,而不是进入 RDBMS 并自己查询表.

如果可以完全避免在服务之间共享信息,那么耦合度会更低。

(天真的例子:订单履行需要知道订单何时支付;所以它需要一个关联id,但它不需要任何其他账单明细。)