How to ensure data is saved in Couchbase?

Viewed 37

I'm implementing strong data consistency between two applications, one of which uses Couchbase as its storage.

What is the right way to check if data sent from app1 to app2_with_couchbase is actually persisted to inform app1? Database could be queried periodically to confirm, but there is probably more elegant approach. I'm using a standard Couchbase client for Java.

1 Answers

Are you in a situation where you expect data not to persist periodically due to an unstable application or Couchbase cluster, or are you just being extra careful?

In either case, what you're probably looking for are Durability options. For example:

collection.upsert("my-document", JsonObject.create().put("doc", true),
            upsertOptions().durability(DurabilityLevel.MAJORITY));

DurabilityLevel has multiple options: Majority, MajorityAndPersistToActive, PersistToMajority, and None.

For more details on which ones you should choose and why, check out the docs on durable writes.

Also note that if you're on an older version of Couchbase (pre-6.5 I think), there are still some durability options, but they are all "client checked" options, which means there are some edge cases (which may be very infrequently encountered).

Related