Inert Detritus The Internet's dust bunnies

Posted
27 August 2009 @ 9am

CouchDB, and Achieving Consistency

What happens when you change the same document in two different databases and want to synchronize these with each other? CouchDBs replication system comes with automatic conflict detection and resolution. When CouchDB detects that a document has been changed in both databases, it flags this document as being in conflict, much like they would be in a regular version control system.

This isnt as troublesome as it might first sound. When two versions of a documents conflict during replication, the winning version is saved as the most recent version in the documents history. Instead of throwing the losing version away, as you might expect, CouchDB saves this as a previous version in the documents history, so that you can access it if you need to. This happens automatically and consistently, so both databases will make exactly the same choice.

CouchDB: Eventual Consistency. [emphasis added]

Every application that does syncing should support some notion of “revisions”.

It takes only one sync algorithm mistake or a bad conflict resolution approach to suffer data loss. As more apps become “revision-aware”, like Dropbox does so well, there’s many more novel things to be achieved with it, and this is one of them.


1 Comment

Posted by
natevw
27 August 2009 @ 9am

I very much agree that syncing and revision history should go hand-in-hand. It’s accepted that users make mistakes and need undo. It’s pretty clear that in syncing, the computer may make a mistake that needs undo as well.