'Azure Cosmos DB multitenancy Java SDK

We are currently looking into best practices concerning Cosmos DB and its Java SDK in combination with multitenancy. We have a simple Spring Boot based Java service that is providing REST interfaces for CRUD operations on data in a Cosmos DB using the SQL API. Now we need to introduce multitenancy into it. The tenant classifier will be read from a JWT when receiving a REST request and be available in the requests Thread Local context.

Current considerations are to have the data of one tenant in either a separate container or a separate database under one database account. As described in the MS document Multitenancy and Azure Cosmos DB.

Having all data in one container using the tenant classifier as a partition key will not work due to the amount of data, plus we need separation of the data to prevent the noisy neighbour problem.

Are there any best practices on how to design the data access layer - also in regards of performance pitfalls?

Our understanding at the moment

  • Use one CosmosDBClient per application (as the initialization takes time)
  • Container names are defined on entity level (@Container())

The official sample create individual repositories and database configs Azure Spring Boot Cosmos Samples which sounds wrong to me

Basically

  • Should we create on CosmosDB client and dynamically (how?) set the container name or database name before executing a CRUD operation?
  • Should we create separate clients for every tenant and re-use those instances?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source