42
Views
1
Comments
Mobile app sync creates duplicates on server if the connection fails or times out
Application Type
Mobile
Service Studio Version
11.54.5 (Build 62302)
Platform Version
11.19.0 (Build 38072)

The Mobile app sync creates duplicates on the server if the connection fails or times out before the data syncs back to the device. 

I am a bit rusty with mobile sync but I would have expected the server to roll back the db transactions in this case. 

Is it a case of not having the correct exception handling in the correct place, or is there something else obvious I should have done to prevent this behaviour

A clearer discription of what is happening

1) The records are created on the device. 

2) The sync is immediately triggered

3) The records are sent to the server and created successfully

4) The device loses connection (or times out) before the server records are able to be sent back to the device (I caused this to happen by debugging the sync and triggering airplane mode at the end of the server action flow)

5) The data is on the server but the data on the device still has the sync flags showing that it is on the device and needs to go to the server (isFromServer = false)

6) When a syncronisation is started again, the records are created on the server again, causing duplicates.

It occurs to me that just checking for duplicates on the server during the sync could be a solution, but I am concerned that if the server sync fails and doesnt create all of the required records and the joins between them, then data integrity may be lost.

Thanks! Any help is greatly appreciated. I will post the action flows below and try post an oml if it is needed.



2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Mitchell,

Mobile sync should always consider that during sync the connection may be lost, so there must always be some method to recover from this situation. It very much depends on your situation (especially what type of data you have, and what the data model looks like) what is the best way to solve this. Some pointers:

  • Always send a mutation date to/from the mobile device, and store this time stamp on both sides. When syncing, if the time stamp is equal, there's no need to recreate or overwrite;
  • If you have multiple entities to store the data in, make sure you always either store all the data for a data item, or none at all. If the data is distributed this can be a pain, but if you store everything in an OS database it's somewhat easier;
  • You could, especially server-side, keep logging entities to track what has been synced and what hasn't (and when), so that it's easier to determine what still needs syncing and what not. With large volumes of data this may be faster than querying the actual data entities.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.