I would say that your choice depends. You really have three options:
One database to all their rules ... (your choice 1)
Of course, adding a TenantId column TenantId it easier to add new tenants (users), but there are some disadvantages:
- You have to be careful that each query filter from TenantId. It would be very easy to accidentally forget TenantId in the right place and return the other tenant details.
- All top parent tables must include TenantId. This is not only your master data, but also all the parent data related to the tenant.
- Tenants cannot be in different versions of the scheme at different times. Suppose, for example, that you are making some changes to the data schema in version 1.1 of your application. If all tenants are in the same database, each should be updated at the same time, whether you want them or not. In addition, if you use a single database, you are almost obliged to use one site, because you want the site and the scheme to remain in sync. If you do this, you cannot, for example, instruct someone to upgrade to get a new feature. Functions should be built as plugins, not versions depending on the version, which may not be bad, but from the very beginning it should be an informed decision.
- This can be a daunting task for sharing tenant data if they want to have a copy of their data or want to post their own data or if you want to move them to another database server. Since all resources are divided, you may encounter a situation where one tenant chews resources through reports or traffic, so you want to transfer them to your own database server (and sell them this advantage). In addition, I came across situations where tenants want to get a copy of their data, which they can download on their own. If all the data is in the same database, this can be a daunting task.
If you are going to sell to corporate clients, I would not go this way. However, if you plan to add thousands and thousands of end users as tenants, where you do not need to provide their data, then using one database is probably the right approach.
Tenant segment according to the scheme (for example, Tenant1.Table1, Tenant1.Table2 ... Tenant2.Table1, Tenant2.Table2 ...) (I consider your choice 2)
IMO, this is a more complex version of the simple use of individual databases. The advantage is that maintaining one database is a bit simpler, but besides this, the same problems arise as using separate databases.
Tenant database segment
For corporate clients, I found that in the end it turns out to be the easiest. This eliminates the possibility that the tenant will see incorrect data (if the connection string is incorrect). This allows corporations to host their own system. This allows tenants to be on different versions if each tenant has different virtual applications. This makes it easy to allocate resources, back up and restore. This is only (but not insignificant) minus - this is the time cost of installation (and, consequently, financial costs). It can be painful to add databases when you get a new client. Technically, it can be automated, but it is still a pain.
So, ultimately it depends on your target customer. If they are standard users, I would go with the approach “One database to manage everything” and make sure that you do a lot of code reviews and automatic testing. If these are corporate clients, especially large corporate clients, then I would consider separate databases for each tenant.