Multi-tenancy analysis on the accumulation--saas of Java engineering

Source: Internet
Author: User

Recent projects involved a more in-depth part of the definition of customer relations, in our discussions, we decided that the use of service provider model is that we are the basic service providers, by the customer portfolio services, to provide customers with cloud-based service support! This naturally leads to the following concepts:


SaaS Encyclopedia:SaaS is the abbreviation of Software-as-a-service (software as a service), with the development of Internet technology and the maturity of application software, a completely innovative software application pattern has arisen in the 21st century. It has a similar meaning to "On-demand software" (On-demand software), the application service provider (ASP, application Service provider), hosted software (managed software). It is a mode of providing software through the Internet, the manufacturer unifies the application software on its own server, the customer can order the required application software service through the Internet to the manufacturer according to their actual demand, and pay the vendor according to the amount and time of the service ordered. And through the Internet to obtain the services provided by the manufacturer. Users do not need to purchase software, but instead of renting web-based software to the provider to manage business activities, without the need for software maintenance, the service provider has full control and maintenance software, software vendors to provide customers with Internet applications, but also provide software offline operation and local data storage, Allows users to use their ordered software and services anytime, anywhere. For many small businesses, SaaS is the best way to adopt advanced technologies that eliminate the need for businesses to purchase, build, and maintain infrastructure and applications.


So, the question is, how to provide an efficient, secure basic data service for different users? In the face of the problems we think of, certain people have met the principle, we have searched for a solution:


Multi-tenancy (multi-tenancy)

This means that a running instance of one application serves multiple client (tenant) architectures at the same time. This is a very common solution for SaaS.


About the multi-tenancy implementation, there are about three kinds: "N tenants N Databases", "N tenants 1 Database n schema", "N tenants 1 databases 1 schemas"


1. Detaching the database (separate Databases)

"N Tenants N Databases"

The data for each tenant is saved in a physically separate database instance. The JDBC connection will specifically indicate each database. A common application method is to define a JDBC connection pool, and the currently logged on user is associated with a "tenant identifier" to select a JDBC connection.
Benefit: The data model of the application can be easily extended (discussed later) to meet the individual needs of the tenants, and recovering the tenant's data from the backup on failure is a relatively straightforward process.
Disadvantages: leads to higher equipment costs, as well as the cost of maintaining and backing up tenant data.
Relatively high hardware, maintenance costs make it suitable for customers who are willing to pay extra for increased security and customization. For example, customers in areas such as banking or medical records management tend to have strong data segregation requirements, and even have to not provide each tenant with its own separate database.


2. Shared database, separate schema for each other (GKFX, separate Schemas)"n tenants 1 databases n schemas"
Each tenant has its own table, which can be understood as a separate table for each tenant. Each tenant has its own set of tables in the shared database. When the customer subscribes to the service for the first time, the provisioning subsystem creates a discrete set of tables for the tenant and associates it with the tenant's schema. You can use the SQL create command to create a schema and authorize the user account to access it. The application can then create and access the schema of the tenant within the table using the Schemaname.tablename convention:
CREATE TABLE contososchema.resumes (EmployeeID int identity primary key,resume nvarchar (MAX));
After creating the schema, it is the default schema setting for the tenant account:
ALTER USER Contoso with default_schema = Contososchema
The tenant account can access tables within its default schema, just by specifying TableName instead of using Schemaname.tablename. In this way, a set of SQL statements can be used by all tenants to access their own data, for example: SELECT * FROM Resumes

Advantages:

This is an easy way to implement, and tenants can extend the data model just like individual database methods. (created tables but once they do not meet the requirements, tenants can add, modify the table)

This approach provides a moderate level of logical data isolation security, although not as a fully independent database, but can support a large number of tenants on each database server.

Disadvantages:

It is difficult to recover a tenant when the data fails. If each tenant has its own database, restoring the data for a single tenant means simply restoring the database from the most recent backup. This approach means restoring the entire database with backed-up data, regardless of whether the data for each tenant on the same database is compromised. Therefore, to restore the data for a single customer, the database administrator might need to restore the database to a temporary server and then import the customer's table onto the production server-a complex and potentially time-consuming task.



3. Sharing database, sharing schema (GKFX, shared schema)"n Tenants 1 databases 1 schemas"
This method is the simplest one. Each table uses an identifier for the tenant. All tenants share a set of identical tables, and a tenant identifier ID relates each tenant to the row it owns.

Advantages:

Minimum hardware and backup costs, because it allows each database server to serve more tenants. However, because multiple tenants share the same database tables, this approach can lead to security issues, and you must strive to ensure that tenants are never able to access other tenants ' data even in the event of an accident.

Disadvantages:

The process for the tenant to restore data is similar to the shared schema method, to reinsert the staging database into a single row into the production database. If there is a very large number of rows in the affected table, this can cause significant performance degradation for all tenants of the database service. The shared architecture approach can serve a large number of tenants and potential customers with a small amount of servers, if they are willing to get security at a lower cost.

Each crud needs to use the corresponding tenant identifier Id.sql to become complex.


Summary:

The concept of SaaS long ago, is that we deploy N programs to complete the service for multiple users, but in our program maintenance, increased too much cost, in line with the hardware can solve the problem, the software can solve, with this concept, the actual is not a new concept, It's a solution to solve a group of problems! Today we have enough ammunition, in the next blog, let's make it come true!

Multi-tenancy analysis on the accumulation--saas of Java engineering

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.