Kapil Earanky
Kapil Earanky

Reputation: 211

Concurrent updates using XDCR Couchbase

I'm testing Couchbase for an application and ran into a few doubts with XDCR, I read Conflict resolution in XDCR. but wasn't exactly sure about what would happen in the following scenario:

I have two clusters (1 server each, say S1 and S2) on which I'm replicating a bucket both ways using XDCR.

If S1 and S2 were to modify the same document simultaneously, how would the resulting update be decided, considering both of them make a single change to the document? Would the answer change if they made a different number of modifications to the document?

Upvotes: 0

Views: 144

Answers (2)

mikewied
mikewied

Reputation: 5333

Couchbase currently uses revision based conflict resolution. That means that the document that got updated most times before conflict resolution takes place will win. If documents on both sides get updated the same amount of times then one of them will be chosen randomly to win. For example:

S1: Updated once, S2: Updated twice. S2 wins
S1: Updated twice, S2: Updated once. S1 wins
S1: Updated once, S2: Updated once. Random winner

When using Couchbase XDCR with active-active replication I would recommend that for most use cases you only update a specific set of documents in one cluster and the other set of documents in the other cluster to avoid issues with simultaneous writes.

Also, as you can see above this conflict resolution model may only be beneficial for specific use cases. In the future more conflict resolution models will be introduced and you will be able to choose the one that best fits your use case. A "Last Write Wins" model should be added in the near term and this model will use vector clocks in order to provide more fine grained conflict resolution.

Upvotes: 1

Roi Katz
Roi Katz

Reputation: 575

Basically if they have the same number of revisions - both will be "correct" as it's an Active-Active system. So you you made changes in S1 and in S2 at the same time - nobody will get the changes. Once S1 or S2 will update again the other server will get the updated document.

Upvotes: 0

Related Questions