Client-server synchronization over REST

后端 未结 2 1271
再見小時候
再見小時候 2021-02-01 10:53

This question is about what I think is a very common problem in Android / iOS development but I haven\'t found any \"standard\" solution yet.

Let\'s say we have a fairly

2条回答
  •  渐次进展
    2021-02-01 11:50

    Currently I am working on the same task - building the Android app which would sync info with a central SQL database using Azure Mobile Services. The sync strategy is to support bidirectional sync from multiple clients to ensure data consistency whereas only incremental changes will be exchanged.

    Let me provide my solution to your problems. I recently wrote a blog post about sync algorithm to support this scenarios.

    The sync logic will be managed on the client side because of REST API communication. Each table participating in the sync process will have the corresponding REST Api methods for CRUD operations.

    For your first problem (consistency) – the solution is to download data on the client in correct order. E.g. first parents, then children to avoid problems with referential integrity. In case of network problem the client would have to sync again to get the rest of data.

    Second problem (download only incremental changes) – the solution is timestamp (as Kevin mentioned in his answer below). But I would suggest using globally incremented value maintained on the server side to avoid issues with timestamp differences between clients and server. The rowversion of SQL Server is quite good candidate for this.

    Third problem (data integration from the client) – using Dirty flag in the client tables would help to differentiate the records required for upload.

    You might also need to introduce the Delete flag on both sides to handle deletes between multiple clients.

提交回复
热议问题