mercredi 6 décembre 2017

Synchronizing client with server c#

Scenario

A client app generates data and stores in database on same machine and the same client app after every 10 minute the generate data has to be pushed to server and store it in database. There are multiple clients working together (take Point of sales terminals in a grocery store as an example) so there's a chance of synchronization on first terminal being stuck while second terminal is synchronizing with server. Using .NET 4.0, C#, Windows Forms, EF and DDD as design approach.

Currently I've a BackgroundWorker that's alive all the time and every tenth minute it starts a new thread that extracts records from local database and constructs required objects and send them to server. The spawned thread gets terminated as soon as there are no records in the queue.

Challenge

Now, I've multiple clients doing the same to one database and there is high chance the start time for synchronization occurs of two or more terminals occur same time (or when one thread's in between pushing the records to server) and there will be conflict.

One Possible Solution

Give server the privilege to rights to decide which client can synchronize its data with server. Every client wanting to synchronize would poll the server to see if there is any sync activity? If no, start synchronization or put the client on hold until server finishes serving the request of first terminal.

Let me know what do you think of this strategy or suggest the other best way to do this. :)

Aucun commentaire:

Enregistrer un commentaire