CouchDB, and achieving consistency
What happens when you change the same document in two different databases and want to synchronize these with each other? CouchDB’s 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 isn’t 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 document’s history. Instead of throwing the losing version away, as you might expect, CouchDB saves this as a previous version in the document’s 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