Multi tenanted SAAS Application

Hi all,
We are in the process of designing a multi-tenant application. During my research, I found out there are a few approaches that we can follow.

  1. Database per tenant
  2. Collection per tenant
  3. Everything in one database and no collection separation, use a field to separate

I believe Approach 3 would not work for us since this application needs to scale to 1000s or 10,000s of tenants.

I want to know
A) what are the limitations and advantages of approaches 1 or 2? are there any performance limitations or cost-wise issues in each approach?
B) what is the most recommended practice. we are planning on using MongoDB atlas and everything needs to be handled programmatically.
C) how we can limit access control in each approach, however this also needs to be done programmatically.

Thank you!

Welcome @dushan_Silva! :sparkles:

A) If you use one collection per tenant you will likely end up having data modeling issues. Normally you use collections for entities like users or orders etc. If you only have one collection you would struggle to store different entities in there.

So you can choose to have one database per tenant or use ids to separate data. When you are scaling up you could shard using the tenant_id thus spreading out the load across multiple replica sets…

B) I’ll let someone else handle this one with more detail aside from what I’m saying as answers for A and C.

C) Since you are using MongoDB Atlas, you can control access based on field values using Realm Rules.
If you go with approach 1 you can control access on a database or collection level. So you could use that to restrict access for a database per client for your scenario.

Cheers,
Naomi

Thank you Naomi, I have one more question. Is it possible to search the content stored within a file which is stored in MongoDB? for example if I store a pdf file in MongoDB is it possible to do a search for a keyword within the file?

Not that I know of I’m afraid

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.