What exactly is the difference between REQUEST_PLUS and STATEMENT_PLUS ScanConsistency in Couchbase?

Viewed 815

I couldn't understand the different between a request and a statement and how consistency is related to each of them.

2 Answers
  • RequestPlus ensures all documents at the time of the query have been indexed.
  • AtPlus (or StatementPlus) ensures that the specified documents have been indexed.
    • This allows for Read Your Own Write without delaying for other writes.

For example:

  1. Bucket B contains one document.
  2. SELECT COUNT(1) FROM B -> result is 1.
  3. You insert a document with ID a
  4. Another document is inserted with ID b
  5. SELECT COUNT(1) FROM B
    • With "Not Bounded" (default) consistency -> immediate result of at least 1 is returned.
    • With "AtPlus" consistency, specifying additional state that a was mutated -> result of at least 2 after document a is updated in the index.
    • With "RequestPlus" consistency -> result of 3 after indexing has completely caught up.

Some additional notes.

For better or worse, Couchbase allows you to control when indexes are updated following executing a query. Quite unfortunately, the default behavior when executing a query is a kind of 'eventual' consistency.

In practice, this means that sequential queries, where the second query depends on the results of the first query, are highly likely to fail with inconsistent results, as the indexes used to perform the second query have not yet been updated.

The choice of eventual consistency as the default option in Couchbase is bewildering to me. Performance is important. But it's arguably rarely, if ever, more important than consistency (except for bulk insert-and-forget operations), and especially not in a web application context.

So unless you're using Couchbase as a pure data warehouse (mostly writes, few reads), then you'll need to remember to manually set consistency to REQUEST_PLUS for the vast majority of your queries, or prepare for madness.

Related