[英]How to design a pub-sub system where there can be multiple publisher for same entity?
Consider the following situation: 考虑以下情况:
So information can be published from S1 and S2. 因此,可以从S1和S2发布信息。
Suppose a user initially have name N1. 假设用户最初具有名称N1。
At time t1, sales person updates name from N1 to N3. 在时间t1,销售人员将名称从N1更新为N3。
Now S1 consumes event from S3 and updates name to N3. 现在S1从S3消耗事件并将名称更新为N3。 S2 consumes event from S1 and updates name to N2.
S2从S1消耗事件并将名称更新为N2。
In S3 name can be anything N2 OR N3 depending which event is consumed first. 在S3中,名称可以是N2或N3,取决于首先消耗哪个事件。
This has caused a lot of data consistency among various system. 这导致各种系统之间的大量数据一致性。
In ideal system there is only one publisher but due to requirement we had to add publishing events from Sales panel. 在理想的系统中,只有一个发布者,但由于要求,我们必须从“销售”面板添加发布事件。 What can be done to minimize data inconsitency?
可以采取哪些措施来最大限度地减少数据不一致?
The problem seems to be in deciding who is the master of User data, because right now S3 is trying to serve two masters. 问题似乎在于决定谁是用户数据的主人,因为现在S3正在尝试为两个主人提供服务。
S1 --> S3
S2 --> S3
Let's make S1 the master of User data, so that any other system which accepts that data (eg S2) is responsible only for updating the master. 让S1成为用户数据的主人,这样接受该数据的任何其他系统(例如S2)只负责更新主数据。 This way S3 gets User data from a single source (the master of User data).
这样,S3从单个源(用户数据的主站)获取用户数据。
S1 --> S3
S2 --> S1 --> S3
The master is responsible for both consuming and producing the data that it owns. 主人负责消费和生成它拥有的数据。 Another system may consume (and even store) the same data, but it can only produce to the master .
另一个系统可能消耗(甚至存储)相同的数据, 但它只能产生给主数据 。 No system can produce data that it doesn't own to any system other than the master of that data.
没有系统可以生成除了该数据的主数据之外的任何系统不拥有的数据。
It doesn't really matter which system is the master, as long as there is only one. 只要只有一个系统,哪个系统是主系统并不重要。 It doesn't really matter how many systems store copies of the data, as long as there is only one master.
只要只有一个主数据,有多少系统存储数据副本并不重要。 Having each system master one type of data is probably more scalable than a single master for all data.
让每个系统掌握一种类型的数据可能比所有数据的单个主数据更具可扩展性。
Let me rephrase it once again.. 让我再说一遍..
In this scenario i would go with Master DB / System which will be single point of data source for every system. 在这种情况下,我将使用Master DB / System,它将成为每个系统的单点数据源。
If any system want to change data then data 1st need to update on Master Db / system then it should propagate to other system to reflect the changes. 如果任何系统想要更改数据,则数据首先需要在主Db /系统上更新,然后它应传播到其他系统以反映更改。
for Pub-Sub I will follow Fan-IN and Fan-out method. 对于Pub-Sub,我将遵循Fan-IN和扇出方法。
In this way you can achieve Data consistency between systems. 这样,您就可以实现系统之间的数据一致性。 Only thing you need to take care is delay in this process, which could be arise if any system fails.
只有你需要注意的是这个过程的延迟,如果任何系统出现故障,可能会出现这种情况。
Hope I have answer your query. 希望我已经回答了你的问题。
Maintain one table to keep track of all latest updates (Latest One day updates). 维护一个表以跟踪所有最新更新(最新一天更新)。 Assuming that all updates can be propagated to all other systems via pub/sub system within a couple of minutes eventually.
假设所有更新都可以在几分钟内通过pub / sub系统传播到所有其他系统。
All systems should contact this primary source before updating the entry (for fields like name, email and contact number) 在更新条目之前,所有系统都应联系此主要来源(对于名称,电子邮件和联系电话等字段)
If there is already an entry in that primary source table then need to verify that which is the latest one. 如果该主要源表中已有条目,则需要验证哪个是最新的。 If their is newer entry then need to alert to the user that there were some recent updates happened to the same record, do you still want to update it.
如果它们是较新的条目,则需要提醒用户相同记录中发生了一些最新更新,您是否仍想更新它。
If there is no entry then you can easily update the data with the new data and insert one entry into these primary source table. 如果没有条目,则可以使用新数据轻松更新数据,并在这些主要源表中插入一个条目。
Whenever any system processes updates via pub-sub then it should update only if there are no new updates happend to the same record. 每当任何系统通过pub-sub处理更新时,只有在同一记录中没有新的更新发生时它才会更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.