I need to solve the same problem, and also consider options. Since I have many years of experience creating multi-tenant SaaS applications, I was also going to choose the second option based on my previous experience with relational databases.
During my research, I found this article on the mongodb support site (a way back has been added since it left): https://web.archive.org/web/20140812091703/http://support.mongohq.com/ use-cases / multi -tenant.html
The guys said that they are avoiding 2 options at all costs, which, as I understand it, is not particularly characteristic of mongodb. I got the impression that this applies to most of the NoSQL databases I have studied (CoachDB, Cassandra, CouchBase Server, etc.) due to the design of the database.
Collections (or groups, or as they call them in different databases) are not the same as security schemes in a DBMS, despite the fact that they behave like a container for documents that are useless for applying the correct separation of clients. I could not find a NoSQL database that could apply collection-based security restrictions.
Of course, you can use mongodb role-based security to restrict database / server access. ( http://docs.mongodb.org/manual/core/authorization/ )
I would recommend the 1st option when:
- You have enough time and resources to deal with the complexity of designing, implementing, and testing this scenario.
- If you are not going to have big differences in the structure and functionality in the database for different tenants.
- The design of your application will allow tenants to make only minimal adjustments at runtime.
- If you want to optimize space and minimize the use of hardware resources.
- If you are going to have thousands of tenants.
- If you want fast and at a good price.
- If you are NOT going to back up data based on tenants (keep separate backups for each tenant). This can be done even in this scenario, but the effort will be tremendous.
I would go for option 3 if:
- You will have a small list of tenants (several hundred).
- The specifics of the business requires that you can maintain large differences in the database structure for different tenants (for example, integration with third-party systems, import-export data).
- The design of your application will allow customers (tenants) to make significant changes during the execution of the application (adding modules, setting fields, etc.).
- If you have enough resources to quickly scale with new hardware nodes.
- If you need to keep versions / backups of data for each tenant. Also, recovery will be easy.
- There are legislative / regulatory restrictions that force you to keep different tenants in different databases (even in data centers).
- If you want to make full use of mongodb's predefined security features, such as roles.
- There are large differences in size between tenants (you have many small tenants and few very large tenants).
If you post more information about your application, I may be able to give you more detailed advice.
Ruslan Kiskinov Apr 21 '14 at 17:54 on 2014-04-21 17:54
source share