gpt4 book ai didi

微服务,CQRS : Eventual consistency vs Strong consistency(Read after Write consistency)

转载 作者:行者123 更新时间:2023-12-04 03:36:59 29 4
gpt4 key购买 nike

使用 CQRS 和事件存储,微服务之间的编排提供了最终一致性,其中一个微服务中的更改需要一点时间才能传播到其他相关的下游系统(基本上是其他微服务)。
如果数据非常关键以至于两个微服务都应该对数据具有强一致性,那么有哪些选择?我能想到的一种选择是像数据网格一样通过缓存写入,但这在分布式系统中会非常脆弱。

最佳答案

强一致性在分布式服务中很难,在微服务中更难,因为它们拥有自己的数据。这意味着您只能在微服务内部具有强一致性。

但是,您可以使用 Saga/Process manager 将关键操作建模为一个复杂的过程。 .这意味着您使用 Saga 以您的业务可接受的方式来协调操作的完成。例如,您可以使用类似 Reservation pattern 的内容。

This pattern enables managing the resource allocation process in an orderly manner by implementing a two pass protocol - somewhat similar to a two phase commit. During the first pass, the initiator asks each participant to reserve itself. If the initiator gets an OK from all the involved services - within a timeout - it will start the second pass, confirming reservation to all the participants.

关于微服务,CQRS : Eventual consistency vs Strong consistency(Read after Write consistency),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48294450/

29 4 0