Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing correct approach to build a muti-tenant architecture with Azure Cosmos DB (MongoDB)

I am little confused in choosing the suitable approach of creating database/collections for a multi-tenant system in MongoDB in CosmosDB API. I would have 500 tenants for my application, where each tenant's data may grow up to 3-5GB and initially each tenant may need minimum RUs (400 RU/s).

For this use case i would have few options to go with: 1. PartitionKey (per tenant) 2. Container w/ shared throughput (per tenant) 3. Container w/ dedicated throughput (per tenant) 4. Database Account (per tanant)

Considering the Performance Isolation, Cost, Availability and Security, may i know which option would be suitable for the mentioned use case ?. Please let me know your inputs as i have less exposure to NoSQL and Cosmos track.

like image 410
Guru Prasad Avatar asked Apr 15 '20 06:04

Guru Prasad


1 Answers

The answer is potentially multiple options and it depends on your specific tenant use cases.

Tenant/Partition is the least expensive with a marginal cost per tenant of zero. This is a great option for providing a "free-tier" in your app but you can scale this up to a paid tier for your customers too. Max storage size is 20GB. With this scheme you will need to implement your own resource governance. You will need to ensure customers are not "running hot" and consuming throughput and storage that is drastically out of line from other users. However if you're building a multi-tenant app, resource governance is something you should already be doing.

Tenant/Container is more expensive at 400 RU/s per month ($25/month) which is the minimum throughput for a container. This is ideal when you have tenants that are very large and require isolation from others in the previous tier.

Tenant/Account is same marginal cost as Tenant/Container. This is useful if you have customers that have GDPR requirements that prevent or require replication into specific Azure regions.

Note that I DO NOT recommend Tenant/Container using shared Database throughput. The reason is because with this scheme, all containers share the same throughput which is what you get with Tenant/Partition but performance is not predictable with shared Database throughput so it is not a good choice. Additionally, you are limited to 25 containers per database further making it a poor choice.

Finally, for your app you will need to implement a mechanism to migrate customers from one tier to another. You will also of course require some sort of auth-n/auth-z mechanism. For Cosmos DB you can optionally use our native users and permissions and use resource tokens to secure access to data.

We did a presentation on this last year at BUILD with a customer of ours Citrix who built their own cloud offering on top of Azure using Cosmos DB as their user meta-data store. Definitely worth checking out and will provide you more details and insights, Mission-critical multi-tenant apps with Cosmos DB

PS: if you are building a new service on Cosmos DB I recommend using our Core (SQL) API rather than MongoDB. This is our native service and you will get the best performance and features. Our MongoDB API is the best choice for customers who are looking to migrate and want a fully managed MongoDB experience.

Hope this is helpful.

like image 196
Mark Brown Avatar answered Nov 15 '22 11:11

Mark Brown