Muthamizhchelvan. V
Muthamizhchelvan. V

Reputation: 1261

Need suggestion for Multi-tenant database architecture?

We are developing project using PHP & MySQL in SaaS model, each tenant has the option to create modules for their own, using our Module Creator and Form Builder.

When they are creating new module dynamically we are creating new table for particular tenant. So each tenant has different schema.

I suggested to go with each database of each tenant but my manager wants to keep all the tenant into single DB since we have continues upgrade on our project.

Now my idea is to have 2 DB for each tenant; one is Master DB its common for all tenant and the next one is secondary DB, it is for each individual’s table creation.

Upvotes: 1

Views: 2090

Answers (2)

Jens Baitinger
Jens Baitinger

Reputation: 2365

I would seperate the data of your tenants in seperate DBs. This makes it more difficult implementing bugs so that one tenant can accidently access the data of another. As far as I know there are data privacy acts in at least one country (Germany) that requires seperation of database schemas in multi tenancy systems.

For Migrating the database I would suggest a model like flywire (ok, thats not PHP, but the concept is quite easy and can reimplemented in PHP without big effort)

Upvotes: 0

Dev
Dev

Reputation: 672

There are various ways in which a Multi Tenant app can be designed

1) Single database, single code-base

Use a single database and store all client data in a single database. You will have to add a field like “clientid” in all your tables and modify all your SQL queries to select the correct “clientid”. If you already have a single tenant app, then heavy modification is required in the code.

Advantages: Easy to manage database & updates; no duplication. Disadvantages: If you miss out a “clientid” in the SQL query, it may result in issues with another client.

2)Multiple database, single code-base

Create a separate database for every client. No modification is required to your existing single-tenant codebase. You will only have to modify the configuration file to select a database depending on the client.

Advantages: Very little codebase modification, easy to ensure client data does not get mixed. Disadvantages: Multiple databases to manage so in the event of DB schema updates, you will have to update each and every database.

3)Multiple database, multiple code-base

Create a separate database & duplicate the complete code for every client. No modification required at all.

Advantages: No codebase modification, easy to ensure client data does not get mixed, easy to perform client specific modifications. Disadvantages: Multiple databases/code to manage so in the event of DB schema/code updates, you will have to manually update for each client.

So now you decide which options suits best for your project requirements.

Upvotes: 8

Related Questions