Multitenancy refers to the ability of a software application or system to host multiple independent tenants or organizations, with each tenant having the ability to customize or configure the application or system to meet their specific needs.
In a multitenant application or system, each tenant is typically isolated from the others, with their own separate data, configurations, and customizations. This allows different tenants to use the same application or system without interfering with each other.
Separate schema multi-tenancy is a technique for implementing multitenancy in a database or software application, in which each tenant has a separate schema (i.e. a set of tables and other objects) within the database.
This Poc consist of developing a ToDo App based on Separate Schema Tenancy.
The commands:
First you have to git clone the files by entering in your terminal:
$ git clone https://github.com/Cherni-Oussama/Separate-schema-multitenancy-with-spring-boot.git
Then start the application:
$ docker-compose up -d
-
On startup, the application will configure two
EntityManager
: one for the master and another for tenants. -
The MasterEntityManager will create the Tenant table in the master schema to store each tenant and the corresponding schema.
-
When new tenant is created:
- MasterEntityManager will store the
X-TENANT-ID
and its schema. - Create new schema for the new tenant.
- The TenantEntityManager will populate the new schema with Table dedicated to the Tenant (ToDo table in our case)
- MasterEntityManager will store the
-
When the application received a request:
- the Interceptor will intercept this request
and get the actual tenant
X-TENANT-ID
and ask the TenantContext to store it. - The ORM get the actual tenant from TenantContext and execute the request on the corresponding schema.
- the Interceptor will intercept this request
and get the actual tenant