Client-server synchronization pattern / algorithm?

后端 未结 7 2261
醉酒成梦
醉酒成梦 2020-11-27 08:41

I have a feeling that there must be client-server synchronization patterns out there. But i totally failed to google up one.

Situation is quite simple - server is th

7条回答
  •  温柔的废话
    2020-11-27 09:24

    You should look at how distributed change management works. Look at SVN, CVS and other repositories that manage deltas work.

    You have several use cases.

    • Synchronize changes. Your change-log (or delta history) approach looks good for this. Clients send their deltas to the server; server consolidates and distributes the deltas to the clients. This is the typical case. Databases call this "transaction replication".

    • Client has lost synchronization. Either through a backup/restore or because of a bug. In this case, the client needs to get the current state from the server without going through the deltas. This is a copy from master to detail, deltas and performance be damned. It's a one-time thing; the client is broken; don't try to optimize this, just implement a reliable copy.

    • Client is suspicious. In this case, you need to compare client against server to determine if the client is up-to-date and needs any deltas.

    You should follow the database (and SVN) design pattern of sequentially numbering every change. That way a client can make a trivial request ("What revision should I have?") before attempting to synchronize. And even then, the query ("All deltas since 2149") is delightfully simple for the client and server to process.

提交回复
热议问题