Skip to content

Instantly share code, notes, and snippets.

@nonsensery
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonsensery/9056805 to your computer and use it in GitHub Desktop.
Save nonsensery/9056805 to your computer and use it in GitHub Desktop.
SVN-like sync

Here's one way that a sync system could support signing in-to and out-of different server-side sync accouts.

Initial sign-in

I'm going to consider every note on every device to be unique, initially, since the only way to have duplicate notes would be to have manually copied them between devices.

Since each local note is unique at this point, signing in to a sync account for the first time just adds all of the local notes to that sync account, and records the unique id assigned by the server (keeping the local unique id as well). The sync account "owns" these notes now, and they will appear on any device that signs in to that account.

Other notes from the sync account are downloaded to the device. Each of these gets a local unique id, just like it had been created on the device (and it keeps the server-assigned id).

Signing-out

Since the notes are owned by the sync account the user has two options:

  1. Delete everything. This could actually be useful in the case that you're signing out in order to track an entirely different account, and don't want to bring the notes from the old account with you.

  2. Export (some or all) notes. This effectively creates a new local copy of each note in the old account, although realistically it probably just clears the server-assigned-ids.

Signing back in

In this scenario, signing back in to an account is exactly like signing in initially. Any local notes (newly-created or exported from a previous sync account) are added to the account, duplicates and all.


I've called this a "SVN-like" sync system because it's similar to the way that client-server version control works: You're free to do anything you want locally, but as soon as you connect your local copy to a (remote) repository, it's owned by the repo.

This is different from a peer-to-peer version control system like git, where you can add and remove (compatible) remote repositories at will.

The actual sync mechanics could be anything, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment