Which database structure to use in a Multi-Tenant application?

Manil Kapadia
One9 Tech
Published in
2 min readFeb 1, 2021

A multi-tenant application is an application that can be used by any number of people from different organizations with a single installation, with an added benefit of the data being discreet to each organization.

There are 3 ways in which the developer can structure the database for a Multi-tenant application:-

Image showing all 3 types of database that can be used for a multi-tenant application
  1. Shared schema for all tenants in a single database: Schema for all the tenants is shared in a single database
  2. Separate schema for each tenant in a single database: Each tenant has a separate schema in a single database. For NoSQL databases like MongoDB, this can also be known as a Single collection for each tenant where we create new collections for new tenants in a single database.
  3. Database per tenant: Each tenant has a different database
Comparison of 3 types of database structures

Based on the advantages and disadvantages of all the types shared above, Shared schema in a single database is not the recommended approach for multi-tenant application as the complexity increases exponentially with an increase in the number of tenants. If the cost of the application is not an issue and users are ready to pay for the increased costs, then Database per tenant is the best approach. But, if cost restraint in the application is present, then a Separate schema for each tenant is the recommended approach. But if a developer is using a NoSQL database, then Shared schema in a single database is recommended for starters, and Database per tenant is probably the best approach for NoSQL databases.

We have used the Database per tenant approach in one of the products we are building at One9 Tech. Stay tuned for my next blog to know how I used this approach in building the product.
You can reach out to us at contact@one9.tech in case you have any questions about setting up your architecture.

--

--