S
S
Sergey Sokolov2020-12-24 19:30:54
Software design
Sergey Sokolov, 2020-12-24 19:30:54

How to consolidate data of multiple senders through PubSub?

Several servers publish their local data to the PubSub channel, which must be consolidated and the aggregated result reported to the local clients connected to each of the servers.

For example, voting yes two options: A and B. Three servers c1, c2, c3. At the end of the voting time, each server must show its clients the total voting data. Each server first "knows" only its own data:

.   А   Б
с1  11  22
с2  3   4
с3  55  66


What is the best way to solve this problem: what messages should they exchange after receiving a general signal for the end of the collection of votes?

Two options have come to mind so far:
1. Through the configs, let everyone know how many servers are participating in total - how many results to expect. And something like (pseudocode) Promise.all([s1, s2, s3]).then(...)Each server in the message is "represented" - from whom the data.

2. Just listen to messages with local results and update your local total every time you receive it. If the messages contain "from whom" - this even allows you to refine the results with repeated messages. Before sending to your local clients, when receiving totals, pause for X ms, debounce, so that when messages arrive at approximately the same time, do not bombard clients with frequent updates.

Maybe there is some other "correct" option?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question