When retrieving many Documents at once, What to use N1QL or key-Value or Other way?

Hi! I am just starting my project with Couchbase. :smile:

I have to retrieve 900+ documents at once in my API.
I tried to get documents with Key-Value API, and It took about 9 seconds. I think that speed is quite slow to use in my API.

I also have considered to use N1QL, but I read that Key-value API is much more recommended than using N1QL query on some articles.
**What is the best way to retrieve many documents at once? Is there any common way to do this? :exploding_head: **

Hi @yujineeee

Yes, that’s very very slow. The performance depends on a number of factors such as the number of nodes, quality of hardware and networks, etc., along with how large your documents are, but it should be possible to do much better than that. Could you share a snippet of your code please?

1 Like

In addition to what @graham.pople mentions, the key here is probably to be sure you’re using the async API so you can pipeline these operations.

I’d rephrase that to depending on what you’re doing, the KV API may be much more efficient. If it is retrieval of an object by it’s key/id directly, this can be done very efficiently with Couchbase. So much so that it may even make sense if you’re working to highly optimize to query with a predicate for the IDs, then fetch. That said, there is some development overhead to this, so I wouldn’t necessarily start there, but keep it as an option.

1 Like