Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two-way syncing with iPhone and Web service

Yeah I know there are couple of questions which are related to syncing with iPhone and Web DB but none of them helped me. I also did a lot googling but I rarely found informations about two-way-syncing. Maybe I just used the wrong keywords.


I'm building an App right now and I came up with the idea to add a two-sync to my App and my Web service. My first thought were that it would be ridiculously easy but it turns out to be not that easy at all. I found couple of problems and some solutions to my problems but I would like to hear from you guys if these soultions would create other problems or if these solutions are good or bad.

The idea of my App is helping me sync my notes which I will take on the go with my iPhone and at work or at home with a Web App. Those two ends should always sync'd cause I don't know on any time which device (iPhone or Computer) I will use to take, edit or just read my notes.

What I have on both sides:

For my Web service (and web app) I will use rails and I think mysql on the DB side. On the iPhone I will use a SQLite DB with a Objective-C wrapper (FMDB). Both will exchange data via JSON (using a JSON framwork on iPhone side).

My ideas so far:

  1. Primary key has to be unique on both sides

    As a primary key I will use a UUID. I think it's a unique solution on both sides and it won't make any duplicates (at least I hope).

  2. Revisions for changes of data

    Each change will be saved as revision with a SHA1 key, which I will create from date + note data. The revision object is also including information like:

    • date
    • which note object belongs to this revision
    • changes are made on which device?
    • what chaged? (atually I'm not sure about including this information)

My "solution" so far is I will track every modification (create, update, delete) on a histroy-table with revisions on both sides. On the iPhone side I will first update my history-table from Web DB and then commit my changes to the Web DB. This should work, right?

That sounds not that bad to me but my question here is how can I handle conflicts? I don't want to bother the user with messages how to handle the conflicts.

Roundup of my questions:

  1. Is my "solution" good or bad? What should I change to make it better?
  2. How can I handle change conflicts so the user don't notice them?
  3. Do you have any resources I could read about two-way-sycing?

EDIT:

Thank you all for your answers. I know now that I'm not alone with this "problem" and there is no simple and all fitting solution for all Apps. I assume that I'm doing good with my ideas or solutions so far and I will try to come up with syncing rules.

My idea so far is: I will develop it simple as possible and will use it for my own needs. Solve problems I discovered while using and syncing. After that I will invite my friends to test and solve problems they have. I think this way I can came up with real world rules for syncing my data with Web cause I see what people are actually doing and where problems are.

What you think?

like image 899
OemerA Avatar asked Dec 16 '22 18:12

OemerA


1 Answers

"It depends."

Everyone loves that line in their answers.

Two way sync boils down fundamentally to conflict resolution. And only you as the application designer can come up with the rules for conflict resolution.

Without conflict, syncing is easy.

One way syncing is "easy" because it's just like two way sync, save that the rules for conflict always favor one party. "Make this look like that." Simple rule.

Fine grained two way syncing isn't that hard, you just need to record the specific changes that are made and when they are done, then when you sync, you take that log of changes from each party, combine them in to a single log, and then apply that log to each party starting with the last time they were in sync.

By specific changes I don't mean "record changed", as it's too coarse. Rather you want to know that "lastName" of record changed. It changed at 01/01/2011 12:23:45.

When party A says lastName changed to "Johnson" at 01/01/2011 12:22:45 and party B says lastName changed to "Smith" at 01/01/2011 12:22:46, then "Smith" is the right answer, since it's the latest.

But wait, did you see what happened there? I just pulled a rule out of thin air. "Latest wins". Maybe that doesn't work for you, maybe you have different rules. "It Depends".

So, really, it all comes down to the rules. You can make it as fine grained as you want. There will ALWAYS be conflicts. That's what the rules are for.

So you need to decide what those are for you application.

like image 81
Will Hartung Avatar answered Dec 24 '22 06:12

Will Hartung