Azure / azure-cosmos-dotnet-v3

.NET SDK for Azure Cosmos DB for the core SQL API
MIT License
741 stars 494 forks source link

Patterns/best practices for maintaining multiple cosmos DB account connections #3968

Closed pratyush-prateek closed 1 year ago

pratyush-prateek commented 1 year ago

Background

I am currently working on a project which is a multi-tenant PaaS service based on micro-services architecture. The database layer logic requires writing to multiple different cosmos DB accounts. Think it as a multi-tenant setting where each tenant has a separate cosmos DB account. For that, we need to maintain multiple cosmos clients in memory so that the same can be used to perform the database operation when request comes from different tenants. Also, the compute is shared for all the tenants.

Enquiry

I wanted to know if maintaining multiple cosmos clients in memory could cause an issue here or not, given the maximum number of cosmos DB connections could go up-to 100. Issues being, memory overflow, port exhaustion etc. If yes, what could be a good practice here.

ealsur commented 1 year ago

@jcocchi / @kirankumarkolli This sounds like a good documentation article to tackle, might be worth brainstorming and see what we can come up with.

pratyush-prateek commented 1 year ago

@jackbond

  1. We require multiple cosmos DB accounts per tenant. Not the databases.
  2. The compute is currently shared. We have a primary and a secondary kubernetes cluster (for failover). For simplification, you can assume that the cosmos DB account details such as the account name and endpoint would be a part of the request only so that a request can identify which cosmos account it has to work with.
ealsur commented 1 year ago

@pratyush-prateek Does this help? https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/best-practice-dotnet#best-practices-for-multi-tenant-applications

pratyush-prateek commented 1 year ago

@ealsur Yes, these look good. We can implement some or more of these surely. Thanks !