For about two years now, I’ve been working part-time on an iOS project with a small team of people. The app is structured as a calendar, but unlike other calendar apps this one tells you how much time you have left, how much time you’ve planned and spent on things, and it comes with a tool to track what you’re doing right now (giving you later a history of how you spent your time).
I’m not going to detail what the app can do here. It was released last week, so just go take a look.
For this app I built a synchronization engine. Each device running the app has an independent copy of the database, and each time it connects to our servers, databases are merged together and changes are propagated to other devices. The way it works is interesting, so I’ll elaborate a little.
Our synchronization system is built in a similar way to distributed version control systems (Git, Mercurial, etc.). It has a repository layer used to syncs binary data blocks with other repositories. On top of this the app maintains a SQLite database corresponding to the model. Changes in the local repository are kept in sync with the model database. Changes in the local repository are also pushed to the remote one, and vice versa. And there your iPhone syncs with your iPad.
This systems has two interesting properties in common with DVCS. First, if one repository is lost (whether on the server or on a device), it can be reconstructed from the others. Second, in theory we could do peer-to-peer sync too without a central server even though in practice managing peer-to-pear communications is more complicated and nothing has been done on this front.
It’s interesting to note that the model database is basically a cache of what is in the repository. Whenver the schema for the model database changes (when updating the app for instance), we don’t have to migrate any data: we get rid of the previous model database and rebuilt it from the local repository, just like when syncing.
All in all, I’m quite happy with this system. It took some time to build, there’s still some rough edges, but it was really worth the effort. Give MeoTempo a try if you want to see it in action.