Originally posted by macrophyllum:
Hi,
I have a client/server application and I would like to provide support for synchronization so that a user running the client could "checkout" data, make changes to it on the road and then when they re-connect to the server synchronize the data. Before I dive in, I thought it would be good to get some general ideas about how I should go about doing this.
I thought that I could add a date variable to my model classes, like "lastModificationDate" and then when the user is synchronizing I could compare those dates. Does anyone have any other ideas or pointers?
It's a good start. You should also have a unique id for each object and "synced to" file on the server.
The unique id is obvious - to resolve conflicts when the rest of the data in another object is equal. The "synced to" file records which user/computer has received this record. You need this to track deletions.
For example, say you want to delete a record while working on your PowerBook away from the server. So you delete the record. Then when you sync to the server, you want the server to delete the record, and all other machines when they sync next time.
But if you don't have that "synced to" file, the server will just copy the old record back to your PowerBook again when you sync next. By using that file, when the server gets to that record it can check and think "Hey! that guy had this record before, but not now, he must have deleted it." The server can then mark that record (using the unique ID) as "to be deleted" in its deletion file for any other machine that syncs with the server in the future.
Don't forget to include a "reset" option. If your PowerBook's data is hosed, you don't want it to delete every record on the server next time you sync. Have the default when creating a new data file be a directive that says "give me all the data on the server".
That's about all I can think of for now.