N1QL Scan Consistency Using the Java SDK with Couchbase Server

You can balance performance against consistency in N1QL queries via the Couchbase Java client and the STATEMENT_PLUS (AtPlus) option.

N1QL provides a couple of options for scan consistency, represented in Java by the ScanConsistency enum:

NOT_BOUNDED
REQUEST_PLUS
STATEMENT_PLUS

"Not bounded" being the default, the query engine will grab and return what is in the index right now.
It is the fastest option, but not suitable for "read your own writes" since they may not yet be indexed.

At the other end of the scale there is "request plus" which will — when a query is performed — wait until all of the indexes used have caught up to their highest internal sequence numbers.
This will make sure that you read your own writes, but it might take some time if there is a write-heavy workload.
Also sometimes you are only interested in the last mutation(s) you performed, so waiting for everything else in the index to be updated can mean unnecessary latency.

This is where "statement plus" comes in, also named "at plus".
This option will send some information previously retrieved at mutation time to the query engine which will then make sure to only wait for (at least) those mutations to have been indexed.

If statement_plus is used, mutation tokens need to be enabled in the environment:

There is a downside: from now on every mutation will return a couple more bytes of metadata, so there is slightly more overhead over the network.
Note though that this mechanism is also used for better handling of durability requirements (ReplicateTo/PersistTo), so the user might have it already enabled in their environment.

Now when a mutation is performed the MutationToken is part of the response.
Thus: