0

There are 2 ways to fetch multiple documents in couchbase.

  1. N1QL query
  2. Reactive client (source)

I understand that 2nd has backpresssure and all because of it being reactive in nature. But I want to understand what other functional differences are there between 2 methods? (for example 1 does fire get query to all the shard vs another to a particular shard only etc.). Can someone help me understand functional differences and caveats of using 1st approach over 2nd?

My use case is to do get multiple document by id.

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
best wishes
  • 5,789
  • 1
  • 34
  • 59

1 Answers1

2

The best I can tell, when you use the Flux.fromIterable as in that example, it will use the key-value API behind the scenes. This is different from the N1QL approach in a number of ways that include (but probably aren't limited to):

  1. N1QL can be used to fetch document by other non-document key attributes (e.g. `SELECT * FROM foo WHERE name LIKE '%best wishes%'

  2. N1QL queries will use the Couchbase query service and (usually) the index service and (most likely) the data service.

  3. The key-value API will go directly the the data service.

I think using N1QL to fetch documents by ID may not need to use the index service (assuming you use the right syntax), but will still need to use the query service. So there is some overhead.

Key-value access is always the fastest way to retrieve data from Couchbase. However, depending on your document size, concurrency needs, other operations, and what overhead the Reactive client introduces (if any--I don't know), the difference in overall performance could be anywhere from 0 to way-way-way better.

My gut recommendation is to go with Reactive (and therefore key-value) for your use case of "get multiple document by id".

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121