christostsang
christostsang

Reputation: 1841

Multi-tenancy and custom features per tenant

I am building a web app (using Laravel but it's irrelevant), that will have multiple tenants with each tenant having its own database. The backend and frontend code end will be common.

We all know the benefits of multitenancy with a dedicated DB per tenant, so I will no go over it again. In my case, it fits my needs 100%.

My question:

If a tenant (client) comes to me for customization (ex. an additional feature, alteration of current feature, removal of feature, etc.) how do I execute this? Obviously I can't alter the code for all tenants, so I guess I will need some kind of filtering or settings where I can toggle features on and off per tenant.

Any ideas?

Thanks in advance.

Upvotes: 1

Views: 2404

Answers (1)

Dhrumil Patel
Dhrumil Patel

Reputation: 362

There are couple of ways to implement Multi-Tennancy.

Here I would like to suggest two ways which I implemented previously in my projects.

First Way :

  1. Create the tenant table. Add tenant_id column in every DB table.
  2. Pass the corresponding Tenant id in every request's header part. Backend will get tenant id from header.

Second Way :

  1. Create tenant table with two columns namely tenant_name and tenant_uuid value.
  2. front end send the tenant name in URL like https://tenant1.xyz.com. Create one interceptor which intercept the front end request and get tenant name from the URL. Based on that tenant name you can get particular tenant info from DB.
  3. Now store that tenant info in request context of your application.
  4. you can use that info from wherever you want.

In first way you have to pass tenant id in all layer of application which is not advisable. But in second way you can get tenant id from context so no need to pass it in all the layer.

Now Answer for second question is :

For feature toggling of particular tenant. You can create feature table with columns feature_name, is_enabled and tenant_id.

Now suppose you have to show Dashboard feature to X tenant and do not want to show it Y tenant. Then you just have to do enabled and disabled in this table only.

Upvotes: 3

Related Questions