Data Synchronization: or As I Don't Like To Call It
Data Synchronization: or As I Don't Like To Call It
Requirements
Handle multiple clients: iOS, Web, Desktop... Reduce trafc faster sync mobile trafc is expensive AND extra slow only transfer stuff you have to transfer Reduce the number of requests making multiple requests has a signicant overhead
PER-ITEM SYNC
Client Model
... your stuff ... UUID created modied last_sync is_deleted
Server Model
... your stuff ... UUID created modied is_deleted
metadata
Creating GUIDs
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); CFUUIDCreateString(kCFAllocatorDefault,uuid);
Probability of Clash
n = 70,368,744,177,664 = 246 => 0.0000000004 (4 1010)
annual risk of being hit by a meteorite (est.) = 0.00000000006 (6 1011)
Step 0: Preparation
Request object metadata from server Request only after earliest last_sync Sort it into: Objects only in client Objects only in server Objects in client & server
UPDATE CLIENT.O.LAST_SYNC
UPDATE CLIENT.O.LAST_SYNC
if client.o.modified > server.o.modified { if client.o.is_deleted { server.o.is_deleted = YES delete o from client } else send client.o to server }
UPDATE CLIENT.O.LAST_SYNC
if client.o.modified < server.o.modified { if server.o.is_deleted delete o from client else copy server.o to client } if client.o.modified == server.o.modified
UPDATE CLIENT.O.LAST_SYNC
our conict resolution strategy is based on always choosing the last modied we could use last_sync to detect conicts present conicts to user? user per-attribute modied date to resolve automatically?