Reputation: 1442
When using the .NET SDK of Azure Cosmos v3, the recommendation is using a singleton CosmosClient. However, this client requires the account details. In our case, we are setting up a separate DB account in Azure (so physically a different resource) for each (B2B) tenant. Is it then still recommended having such singleton, or is a single instance per tenant still OK?
Bear in mind, tenants share the same application instance (and thus app memory).
Upvotes: 0
Views: 462
Reputation: 8763
Cosmos client instance is per account. You cannot create a single instance and have it connect to multiple accounts simultaneously.
Generally speaking, multi-tenant apps in the same application instance are designed to be tenant per container or tenant per partition key. Applications which use the Cosmos account as the tenant boundary are often only done when tenants have different replication regions or have other networking or other needs, such as security which can only be managed at the account level.
If this is not the case then I suggest you evaluate what your tenant boundary is. Tenant per account is an expensive option on a per tenant basis. It also has the highest operational overhead.
There is a really good presentation from the recent Cosmos DB Conf which does a really great job explaining how to design multi-tenant apps using Cosmos DB. Definitely worth watching, From the trenches: Building an awesome multitenant SaaS with Cosmos DB and Azure.
There is also another older talk that also talks about options for tenant boundaries which is also really good. The first 20 minutes is the multi-tenant part, Mission-critical multi-tenant apps with Cosmos DB multi-master
Upvotes: 1