What is multitenancy?
Multitenancy, also called multi-tenant architecture, is a software architecture in which a single software instance along with a database serves multiple tenants.
By tenant, we mean either an individual user or, more commonly, a group of users (i.e. organizations) that use the same computing resources of a given application.
Services offered by SaaS (Software as a Service) providers are often based on multi-tenant architecture.
This kind of cloud-based solution allows multiple users to access the same software application and share the same infrastructure. Multitenancy keeps tenants’ data secure, isolated and well-organized within one database. Even though multiple tenants share the same database, they cannot see each other’s data.
The opposite of multitenancy is a single-tenant architecture. It applies mostly to specific industries where a strong privacy of customer’s data storage is required. In a single tenancy environment, customer data is separated from other customers’ data.
To explain what multitenancy is, we use the shepherd metaphor.
Imagine a shepherd who runs a sheep-keeping business. They have a large pasture, so they rent it to other sheep owners. They end up having on their terrain hundreds of sheep from numerous owners. One of their biggest challenges is to figure out who a given sheep belongs to.
The question is: how does the shepherd manage and maintain the barn in order to know exactly where specific sheep are located?
Multi-tenant architecture solves this problem inside SaaS applications or large data centers.
What is multitenancy in cloud computing?
Multitenancy is a very important concept in cloud computing. However, it is worth mentioning that even though the cloud computing and multi-tenant architecture often go hand in hand, those are separate constructs.
Multi-tenant architecture for SaaS applications can be introduced both on local servers and in the cloud. But here we’ll look at the advantages of hosting in the cloud.
If you have an application with at least a few thousand users and a lot of data, you’re probably struggling with performance issues.
To improve the efficiency of your application, it is reasonable to deploy it in a cloud environment rather than on a local server.
Following this logic, when implementing a multitenancy architecture for your application, consider using the cloud.
The reason is simple. It does not impose restrictions when it comes to computing resources.
Most of the modern applications (some of the most popular we are mentioning below) are hosted in the cloud. It allows users to access, for example, their Google accounts and transfer files from various devices.
In brief, running a cloud application in multi-tenant architecture makes it easier, more efficient and flexible.
Multi-tenancy architecture with examples
The most popular instances of multitenancy in SaaS applications are:
- Google Workspace,
What all the above applications have in common is the way they manage user data and users’ access to the application. One of the hardest struggles that a multi-tenant architecture solves is a data separation.
Providing SaaS without the multitenancy architecture would mean that a new setup for each customer would have to be created on a separate application server with its own assigned database.
There would be no common application part for all users, but each client would have a separate application completely isolated from other clients/organizations.
This is a suboptimal solution because it requires installing the same application many times, doing application updates on several servers at once, thus using more resources.
To avoid the above challenges, most of the SaaS providers use multitenancy.
What are multi-tenant databases?
There are three most popular approaches to managing and organizing data in multi-tenant architecture.
To illustrate it, let’s go back to our shepherd metaphor.
In their large territory, a shepherd is in charge of many sheep that belong to different owners. The challenge for the shepherd is to organize the space in such a way that they know which sheep belong to which owner.
In order to keep the sheep safe and well located, the shepherd has to build a barn. They can do it in a couple ways. They have to keep in mind how many sheep and clients they serve, as well as what kind of resources they have.
The shepherd, in order not to confuse the sheep, can choose from three options:
- Put on a collar for each sheep with an owner information label and keep them in a big barn;
- Set up separate boxes inside a single large barn, where each box is assigned to a particular owner’s sheep;
- Build multiple, smaller barns dedicated exclusively to specific sheep’s owner.
Having multiple tenants requires making a proper decision about the data storage at the very beginning of the introduction of the multi-tenant architecture.
We will briefly talk about each type of multitenancy database.
For a more detailed explanation of multi-tenant databases, we highly recommend reading our in-depth introduction to multi-tenant architecture. There, we thoroughly point the differences between each type of databases and also discuss its advantages and disadvantages.
#1 Shared database
A shared database in multitenancy allows distributing users’ data across multiple databases (shards), with all the data for a particular tenant being contained in a single shard.
#2 One schema per tenant
In this type of the data store infrastructure, we create multiple schemas in the same database to provide some level of data isolation to the users. The schema is a separated area inside the database. You can name its subdirectories with tables containing the user’s data, like in the example below.
#3 One database per tenant
In this type of multi-tenancy database, each tenant has their own, dedicated database. Every time a new tenant is added to the system, a new database is generated.
Inside the main server, we have separate databases dedicated solely to specific tenants.
What is the difference between single tenant and multi-tenant?
The main difference between the multi-tenant and single-tenant architecture is the way the software serves its clients.
In the multi-tenant architecture, a single instance of software serves multiple customers. Each tenant shares the same software application. Their data is isolated and invisible to other tenants.
In the single-tenant model, there is a dedicated software serving only a single tenant. With the single tenancy, each client has their own database and instance of the software.
Let’s see how the single tenancy works with an example.
Imagine an accounting company that operates on its own payroll system. The system is hosted on the company’s server and only the employees are allowed to use it on the same software. This is a simple example of a single tenancy system. The key point is that operations are performed only for one organization on its own server.
Benefits of multi-tenant architecture
We looked at the most important aspects of multitenancy. Now, the question is why you should consider this solution.
Here are the key benefits of multitenancy:
- Saves money and time – since the same application and database serve multiple tenants, the cost of development and maintenance is significantly lower. Moreover, you don’t have to neither make changes in code nor set up a new database for each tenant separately.
- Increases efficiency – the multi-tenant architecture allows for the more efficient use of IT resources. The efficiency of the application depends on the type of multi-tenant database you choose.
- Improves performance – with massive amounts of tenants data, users can influence each other’s performance. The third type of multitenancy (one database per tenant) solves this problem. To learn more about good practices, check our article about data scalability, processing, and allocation in multitenancy.
- Makes it easier to manage databases – when an application processes data from multiple tenants, then we need to find a way to manage the huge amount of data. It helps you to know which data belongs to which organization (tenant).
- Allows for easy use from the user’s point of view – users are neither responsible for maintenance, updates, nor infrastructure and data management.
In Stratoflow we have introduced multitenancy to our SaaS product Recostream – a recommendation engine based on machine learning. Multi-tenancy architecture allows Recostream to efficiently service everyone from small customers to large enterprises with thousands of users. As a result, software development and maintenance costs are shared.
Hungry for more? Check our series of articles fully dedicated to Evolutionary Hybrid Multitenancy.