In this proposed solution, we are going to support multiple tenants with different types of multi-tenancy database models in one application.
To achieve this we need to have tenant identifier columns in all tables, and all query should have the association of tenant identifier as criteria.
We will be adding another column to have database identifier along with tenant identifier.
In this example, we have five tenants but T1 & T2 tenants have their own database implementation named D1 & D2 respectively, and T3, T4 & T5 tenant has the common database named ‘CD’/Common Database.
We going to have three databases named D1, D2 and CD, three data sources for these three databases. In application, we going to have the map of tenant identifier and the database identifier. In the persistent layer of the application, we are going to retrieve the tenant identifier from the tenant context and get the data source with respect to it. We will be populating the tenant identifier in each persistence call and all the update, delete and retrieve call will have tenant identifier as criteria along with other criteria.
By this way, we can support multiple multiple types of multitenancy database implementation models.
Business Impact
We can efficiently able to manage different categories of clients like we can group up small clients into a common database. As a result, these small clients will be benefited from shared storage cost and low database maintenance cost. On the other side, big clients could have their own database and it will make sure they can scale well in the future.