[英]How to two-way sync lists with a database?
I'm building a system that needs to keep two external sources in sync with each other and keep a history of these syncs.我正在构建一个系统,该系统需要保持两个外部源彼此同步并保留这些同步的历史记录。 Here's a quick diagram I made to explain my problem:这是我为解释我的问题而制作的快速图表:
If source 1 changes (add, remove, both), when my system runs the periodic sync, I want source 2 to be identical to source 1. The same goes for any changes to source 2. Bearing in my mind that both source 1 & 2 can change independantly between syncs.如果源 1 发生更改(添加、删除、两者),当我的系统运行定期同步时,我希望源 2 与源 1 相同。对源 2 的任何更改也是如此。请记住源 1 和2 可以在同步之间独立更改。
The solution I have come up with so far is to have a central database that saves the content of source 1 & source 2 on first sync minus any duplicates and then replace the content of source 1 & 2 with the content of the database.到目前为止,我提出的解决方案是拥有一个中央数据库,在第一次同步时保存源 1 和源 2 的内容减去任何重复项,然后用数据库的内容替换源 1 和源 2 的内容。
Then on subsequent syncs I would compare source 1 & 2 with the current database and save the new state in a new database.然后在随后的同步中,我会将源 1 和 2 与当前数据库进行比较,并将新的 state 保存在新数据库中。 This way I would keep a history of the state of the database after each sync.这样,我将在每次同步后保留数据库的 state 的历史记录。
So my two main concerns at this point are:所以我在这一点上的两个主要问题是:
I'm mainly proficient in Java and JS if code/pseudo-code is easier to explain.如果代码/伪代码更容易解释,我主要精通Java和JS。 Any help is greatly apreaciated, thanks.任何帮助都非常感谢,谢谢。
I think you would need a distributed cache/in memory data store like Redis/Hazelcast which would make sure both your sources are aware of the changes being made.我认为您需要一个分布式缓存/在 memory 数据存储中,例如 Redis/Hazelcast,这将确保您的两个来源都知道正在进行的更改。 You can just add a listener to this cache and persist it in the database, this would make your data consistent.您可以在此缓存中添加一个侦听器并将其保存在数据库中,这将使您的数据保持一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.