I work on the migration from SDK v2 to SDK 3 in the performance-critical application.
In SDK v2, the recommendation was to use single DocumentClient across for all queries, even in parallel, since this class is thread-safe.
What is the recommendation for SDK v3? In the past we had DocumentClient, but now we have CosmosClient, Database and Container. From the samples I can see that I can reuse Container for multiple queries, but is it safe to do parallel queries on it?
According to the performance tips in https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips, only CosmosClient is thread-safe. Does it mean that I need to create single CosmosClient and a new Container every time when I need to do a query?
CosmosClient, database, and container are thread safe. For the best performance use the same Container for all the operations. Creating a new Container for each call will cause unnecessary overhead.
Thanks. I think it would be worth to clarify it somewhere, for example in https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips. For me, it sounds correct, but I wasn't sure.
@ausfeldt can you do the documentation update?
Most helpful comment
Thanks. I think it would be worth to clarify it somewhere, for example in https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips. For me, it sounds correct, but I wasn't sure.