Suppose process A has a consitent snapshot of some entities. And it is constantly receiving updates for this enteties. Now client B connecting to A and it should receive the consistent snapshot of entities that A has and then it should receive all the updates that A receives.
Normally if it would synchronous request I would take a read lock on A’s snapshot and writelock on A’s updates, which would allow me to transfer state to B.
The question is can we make this process asynchronous? It means that request from B to A is asynchronous?
Can we use CHANDY–LAMPORT or LAI–YANG algorithms here? I’m pretty new to distributed algorithms, so looking for some expertise.
3
Overview
This is one way to solve that problem. imagine a request. It contains information defining the request (is it an update of data, or is it a request for the current data), and way for the requester to be notified that the request has been actioned, and of its results.
Next up, you have a queue. You place the request into the queue, and at some point later you are notified of the results of your request. You can do this synchronously by blocking, but an async callback or event notification is preferable.
Finally you have an agent (or worker) that processes the requests one at a time. That way requests for the current state are always consistent. As its a single thread there is no need for locking on the objects ensuring quick access.
Implementation
This system is usually implemented using a message queue, with a single consumer. see details of using a message queue in an RPC style Rabbit MQ Tutorial. But the pattern can be scaled down to a single application running on a server using a thread safe FIFO queue object.