How to understand multi tenant architecture? (transfer)

Time:2021-2-6

Transferred from: https://www.cnblogs.com/pingfan21/p/7478242.html

Some time ago, the company’s products evolved from architecture to multi tenant architecture. When I first heard about multi tenancy, I was quite puzzled and didn’t understand. But when I gradually look through the materials and develop the functions. Continuously deepen the understanding of multi tenant. Although I only know a little now.

OK, let’s get this straight

1. What is multi tenant architecture?
2. Advantages and disadvantages of multi tenant architecture?
3. Applicable scenarios of multi tenant architecture?

Let’s take these questions to the next reading.

1、 Understanding of multi tenant

Definition of multi tenancy: multi tenancy technology or multi tenancy technology, referred to as SaaS, isA software architecture technologyHow to implement theIn the multi-user environment (the multi-user here is generally for enterprise users), the same system or program components are shared, andEnsure data isolation between users. In short: running a single application instance on a single server, it provides services for multiple tenants (clients). From the definition, we can understand that multi tenant is a kind of architecture, which aims to use the same program in multi-user environment and ensure data isolation between users. So the point is very easy to understand,The key of multi tenant is to realize the isolation of multi-user data under the same program. As for the implementation, we will discuss it next.

Let’s learn more about this: in a multi tenant structure, applications run on the same or a group of servers. This structure is called “single instance”, single instance multi tenant. The data of multiple tenants are stored in the same location, and the isolation operation is realized by partitioning the database. Since the users are running the same application instance and the service is running on the server of the service provider, the user can’t carry out the customized operation, so it’s not applicable to the customers who have special needs for the product, so multi tenant is suitable for the customers with general needs. So the disadvantage is that the user’s customized operation cannot be realized under multi tenant.

When browsing the data of multi tenant, there is another term corresponding to it, that is single tenant SaaS architecture (also known as multiple instance Architecture). The difference between single tenant architecture and multi tenant architecture is that single tenant creates its own software application and supporting environment for each customer. Single tenant SaaS is widely used in applications where customers need to support customization, and this customization is either because of the region, or they need higher security control. Through the single tenant model, each client has a separate database and operating system on a separate server, or uses strong security measures to isolate the virtual network environment. Because this article mainly discusses multi tenancy, so the knowledge of single tenant is simple to understand, not to elaborate too much.

2、 Three schemes of multi tenant data isolation

In the momentIn the era of cloud computing, multi tenant technology provides the same or even customized services for most clients in a shared data center with a single system architecture and services, and can still protect the data isolation of customers. At present, a variety of cloud computing services are such technologies, such as alicloudDatabase service (RDS), Alibaba cloud server, etc.

There are three main schemes for multi tenant data storage, which are as follows:

1. Independent database

This is the first scheme, that is, one tenant and one database. This scheme has the highest user data isolation level, the best security, but the cost is high.  
Advantages:
Providing independent database for different tenants helps to simplify the extended design of data model and meet the unique needs of different tenants; in case of failure, data recovery is relatively simple.  
Disadvantages:
With the increase of the number of database installation, the maintenance cost and purchase cost increase.  
This solution is similar to the traditional one customer, one set of data and one set of deployment. The only difference is that the software is uniformly deployed by the operators. If you are faced with tenants who need a very high level of data isolation, such as banks and hospitals, you can choose this mode to improve the rental pricing. If the price is low and the product is low, this solution is generally unbearable for operators.

2. Shared database, independent schema 
This is the second solution, that is, multiple or all tenants share the database, but each tenant has a schema (also called a user). The underlying libraries, such as DB2 and Oracle, can have multiple schema in one database
Advantages:
It provides a certain degree of logical data isolation for tenants with high security requirements, not complete isolation; each database can support more tenants.
Disadvantages:
If there is a failure, it is difficult to recover the data, because the recovery of the database will involve the data of other tenants
If cross tenant statistics are needed, there are some difficulties.

3. Shared database, shared schema, shared data table
This is the third solution, that is, tenants share the same database and schema, but add tenantid multi tenant data field in the table. This is the mode with the highest degree of sharing and the lowest level of isolation.  
That is to say, every time a piece of data is inserted, a customer’s identification is required. In this way, the data of different customers can be distinguished in the same table.
Advantages:
Compared with the three schemes, the third scheme has the lowest maintenance and acquisition costs, and allows the largest number of tenants per database.  
Disadvantages:
The isolation level is the lowest, the security is the lowest, so we need to increase the amount of security development in the design and development; data backup and recovery is the most difficult, so we need to backup and restore table by table.

If you want to provide services for the most tenants with the least servers, and the tenants accept the sacrifice of isolation level in exchange for reducing the cost, this scheme is the most suitable.  
    
In the process of SaaS implementation, a significant consideration is how to design the application data to support multi tenant, and this design idea is toData sharingSafety isolationandperformanceThere is a balance between them.

Because the underlying library we use is mysql, and to ensure the complete isolation of data, the scheme we use belongs to the first one. Independent database. Because schema in MySQL is his database name. Therefore, every time you serve a user, you need to create a new database. If it is DB2 or Oracle, an independent schema can be used for data isolation in a database, which will save cost and have high data isolation intensity.

3、 Choose a reasonable implementation mode 
What are the main factors to consider in measuring the three modelsIsolation or sharing

  Cost factors

The better the isolation, the higher the difficulty and cost of design and implementation, and the higher the initial cost. The better the sharing, the more users supported under the same operating cost, the lower the operating cost.

Safety factors

Consider the security requirements of the business and customers. The higher the security requirements, the more inclined to isolation.

Considering the number of tenants
The main considerations are as follows
How many tenants does the system support? Hundreds? Thousands or tens of thousands? The more potential tenants there are, the more likely they are to share.  
The average amount of space each tenant needs to store data. The more data is stored, the more likely it is to be isolated.  
The number of end users who simultaneously access the system per tenant. The more you need support, the more you tend to isolate.  
Do you want to provide additional services for each tenant, such as data backup and recovery. The more demand there is, the more isolation there is

Technical reserve
The higher the sharing, the higher the technical requirements.

The above three parts respectively make a summary of the first three problems. Some of the contents in the article are also excerpts from the self-examination materials, which are actually summarized by others very well, so I directly took the wheel to use, aiming to let you and me know more about the multi tenant architecture. Please don’t spray!

The data are as follows:

Architecture comparison of multi tenant and single tenant SaaS http://blog.sina.com.cn/s/blog_ a5ed66830102 wddk.html
Discussion on multi tenant in data layer https://www.ibm.com/developerworks/cn/java/j-lo-dataMultitenant/
Three schemes of multi tenant data isolation in SaaS http://blog.csdn.net/yown/article/details/51288549

Transferred from: https://www.cnblogs.com/pingfan21/p/7478242.html