This document provides an overview of software-as-a-service (SaaS) multi-tenancy. It discusses different types of multi-tenancy including single database for all clients and separate databases per client. It also compares managing a single database versus multiple databases. The document outlines elements needed for a multi-tenant system like tenant identification middleware and separate databases and media directories for each tenant. It recommends using existing Laravel and .NET NuGet packages to implement multi-tenancy that include features like tenant-specific logic and automated middleware.
2. SAAS MULTI TENANTS
• The term "software multi-tenancy" refers to a software architecture in which a
single instance of software runs on a server and serves multiple tenants.
A tenant is a group of users who share a common access with specific privileges
to the software instance.
• The whole point of a multi-tenant app is to give each tenant an individualized
experience while using the same code base
4. TYPES OF MULTIPLE TENANCY
• Multiple Tenants
Single code base and Single DB for all clients (Only One DB for all users)
Single code base for all clients + DB Per client (Db per User)
5. COMPARISON SINGLE DB VS MULTI DB
• Single DB
• Easy to manage DB
• Cheaper
• Less isolated
• More code base modification
• Multi DB
• Little code base modification
• More isolation for each tenant
• More scalable
• Multiple Databases to manage
• More expensive as you need new
database for each new customer
7. SYSTEM ELEMENTS
Each tenant has its own database
and this database is resolved during
the beginning of the request life
cycle. For instance,
System also needs a system
database that keeps track of all of
the Tenants. Each Tenant has a
unique ID which can have multiple
sub-domains.
A Db switcher middleware should be
used to resolve the tenant’s
database.
9. THERE IS 2 DBS SO THERE IS 2 CONNECTIONS IN
THE APPLICATION
1) System connection
• A system database connection which
acts as the master database where
hostnames and tenants are stored.
• Creating admin of the tenants
2) Tenant Connection
• This is maybe the most used database
connection. Data in use by single
tenant instances, not shared with
others, is persisted into the database
using the tenant connection. The
implementation of the tenant
connection ensures that no tenant can
access another tenants data.
• Is the default connection
10. DESIGN NOTES
• You need to have a fallback tenant / domain, to offer a landing page and/or
admin area for your clients to configure their tenant website.
• The default connection will be done in the runtime to the tenant connection
• Have specific media directory for each tenant , separated from the general media
that will be used for all tenants
• The system DB should have 2 tables to describe tenants and their domains
12. IMPLEMENTING MULTI TENANCY THE EASY WAY
You don’t need to do it from scratch there is a Laravel / Nuget package that has it
all
1. For Dot net use the Nuget package 165k downloads
https://www.nuget.org/packages/SaasKit.Multitenancy/
2. For PHP use the Laravel package :
“HynMulti-Tenant”
https://github.com/tenancy/multi-tenant
Documentations:
https://laravel-tenancy.com/docs/hyn/5.3/requirements
13. COOL FEATURES IN HYN/MULTI-TENANT PACKAGE
• Ability to have tenant specific logic overriding the common logic of other tenants
• Very specific and wide range of configurations
• Automation options in form of ready made Middle wares to be used while
occasions such as Maintenance (if a tenant or more is under maintenance) , force
SSL, redirection .
• Full documentation that is easy to understand
https://laravel-tenancy.com/docs/hyn/5.3/structure
14. BEST EXAMPLE FOR RECOMMENDED PACKAGES
• Using SAASKIT in DotNet : https://benfoster.io/blog/asp-net-5-multitenancy
For HYN package start with the documentation it’s awesome !! Then examples in
the documentation then medium tutorials
• Tutorial in Medium https://medium.com/@sadnub/hyn-tenancy-5-2-and-
laravel-passport-a0d11c5a08eb
15. TERMS USED BY HYN PACKAGES
• Tenant , website
• Domain , Hostname,
• Fully qualified domain name fqdn
• Check the tenancy Db ERD