Multi-tenancy is an architecture in which a single instance of a software application serves multiple customers (tenants).
Consideration Points:
Advantages:
Disadvantages:
Approaches:
Given the advantages and disadvantages of each approach, I'd recommend using separate schemas, as they provide the best balance between difficulty of development and cost of running the database layer.
Consideration Points:
- Quantity of tenants
- Performance
- Time of development
- Reliability
- Disaster recovery
- Execution Environment Isolation: Adding, modifying or removing features for one customer should not impact other customers
- Features added for one customer may be applicable for other customers. Hence customization cannot be tied to a single customer. The architecture should allow same features to be enabled and disabled easily for other customers.
- Licenses can be upgraded or downgraded. Features should be grouped so that they can be easily added or removed from a customer execution environment.
Advantages:
- Deploy code without affecting other tenants in the environment
- Feature Customization: Enable features for a single tenant without disturbing other tenants
- Cost-efficient and Financial Benefits
- Efficient Resource Usage
- Easier Set Up and On-boarding
- Easier Upgrades and Maintenance
Disadvantages:
- Data Leakage and Reliability
- More control over backups and recovery
- Migration Ease of Use
- Full control over the environment
- More vulnerable from a security standpoint
- Single point of failure for all Tenants
Approaches:
- Separate databases: Each tenant has its own database. Eg. Maintain different databases for different tenants and connect to the correct database at runtime.
- Separate schemas: Tenants share common database but each tenant has its own set of tables (schema). Eg: Maintain a single database, but different schemas for different tenants qualified by the Company Id
- Shared schema aka Partitioned (discriminator) Data: Tenants share common schema and are distinguished by a tenant discriminator column. Eg: Add a Company Id to all the tables and qualify all queries with a company id.
- Data Sharding
- Hypervisor-level Isolation
Given the advantages and disadvantages of each approach, I'd recommend using separate schemas, as they provide the best balance between difficulty of development and cost of running the database layer.