当前位置:网站首页>Saas. Data isolation and persistence scheme
Saas. Data isolation and persistence scheme
2022-04-22 03:08:00 【Idle cat】
Why data isolation
Someone put Saas Compared with the traditional software service mode, it is : Well drilling and tap water , Drilling a well is a one-time payment. You can use it whatever you want in the future , For tap water, you can pay as much as you use , Not so free .
Again : It turns out that you can't eat food in winter , Each family has its own pickle urn , This urn is only used in winter , Waste space . Someone started building a place to store pickles , The pickle container must distinguish which is from which .Saas When the product is sharing micro Services , Each tenant's own data cannot be shared , Need to be isolated .
Isolation plan
The storage data is mainly relational database , other NoSql The database is a functional auxiliary , Can be divided into :
1. sub-treasury : Different tenants use different libraries
2. table : Different tenants use different tables
3. Add... To the table TenantID Distinguish
4. A mixed solution
Isolate database : sub-treasury
Applicable scenario : Independent deployment requirements , Big customers
advantage : The coding is simple , Single tenant project system development is the same ; Database performance optimization can be differentiated according to different schemes of tenants ; Data backup is easy ;
shortcoming : The cost is relatively high , The database needs to be deployed separately .
Technical realization :Sping Medium AbstractRoutingDataSource;Mycat middleware . Specific implementation reference :
middleware .Mycat First experience _ Idle cat's blog -CSDN Blog
Spring. Dynamic data sources AbstractRoutingDataSource_ Idle cat's blog -CSDN Blog
Shared database , Isolated data structure : table
Different tenants use different tables , Of course, there are business dimensions . such as : Student list , The teacher table
Tenant 1:student_1, teacher_1
Tenant 2:student_2, teacher_2
advantage : The cost of warehouse distribution is too high , Split tables are convenient for both optimization and backup , And it doesn't cost that much
shortcoming : To create a tenant, you need to generate a table, that is DDL operation , Such as : according to student Of Schema establish student_1 surface , It can be more complicated in function :1. When is the table created ;2. Which tables to create ;3. How to distinguish different tables when adding functions ; 4. Base surface Schema How to store All need to be designed . The reference scheme is : When designing functional permissions , Associate tables with functions , Create the tables involved when creating a new tenant , Find the mapping table according to the opened function .
difficulty : Developers don't know when writing code ID,sql I can only write student, And actually implemented sql Need modification :student_1, Reference plan :Saas. Data access control (Sql analysis )_ Idle cat's blog -CSDN Blog
Expand :student and teacher It's all watches , Whether it can also be abstracted as a table ,root The table shows that there are only id,updateby, updatetime ,createby ,createtime ,isdeleted ,remark And other system fields ,student Table is business key by “student” Of root Sub table of ,root_student_1 ( Tenant 1 The student watch of )
Applicable scenario : Generally not used alone , Does not conform to the progressive law of product development ( The development cost is relatively high , At the beginning, the project resources are insufficient ), The actual development is to develop the single system first , The multi tenant transformation will be carried out after the business is verified , Therefore, the cost of sub warehouse at this stage is the lowest .
Shared data structure : Add... To the table TenantID
Scheme description
It's easy to say , Any system seems to add one tenant_id( Tenant id) It becomes saas The system . For example, the original user login is :
select * from student where email='[email protected]'
Change to
select * from student where email='[email protected]' and tenant_id =1;
For complex business saas System , This is very dangerous , And the development efficiency is very low . Think about it. If that programmer writes sql When did you forget to add “ and tenant_id =1” . The result is unimaginable .
scene : It is suitable for scenarios with small amount of data , Small and medium-sized enterprises (smes) , Get customer scenarios for free
advantage : No additional resources are required , You only need to add one field , And then modify Sql Just go
shortcoming : There is no way to optimize according to the tenant , Backing up data by tenant is complex , Fault isolation is difficult
difficulty : The framework level needs to be addressed tenant_id Condition add as well as insert When value Add data in . Refer to the post :Saas. Data access control (Sql analysis )_ Idle cat's blog -CSDN Blog
A mixed solution
A system is relatively large , Basically, not everything will follow one plan . such as :
1. Login logs with small amount of data There is no need to divide the library , table . Add one tenantid It's easy to solve
2. A huge number of logs , Operation behavior table , Must be divided into tables , You may have to divide the table from multiple dimensions , Such as : Period of time , Tenant ID
3. Different business scenarios : Generally, it will be split according to groups , For their own simple maintenance , It's all sub warehouse . Each library will be divided into tables or added according to the actual situation tenantid programme
4. Expand : Metadata driven scheme , The above schemes are from : Business , Operation and maintenance , cost , Development and other considerations , Easy to think of , If it is Saas It can be supported in the middle and early stages , But if you want to answer KA Big customers , For example, there will be characteristic development , Manifested as : Extend the original functions, such as table fields , There are also completely customized pages . How make ? Metadata , stay 【 table . Expand 】 One column and then continue to abstract , To put it simply, put Mysql Medium Schema Tables and data sheets , All moved to Saas Platform self-service control , This scheme is not just a data persistence scheme , It also needs to cover other needs , This is it. Saas The difficulties of , We should have a global vision , Also need to focus a little .
appendix
The term
DB:DataBase abbreviation , database
DS:DataSource abbreviation , data source
TenantID: Tenants in multi tenancy ID , Unique to identify a tenant
Schema: Definition , This article refers to the definition of data table
Lazy loading : Load only when using resources
版权声明
本文为[Idle cat]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220304459783.html
边栏推荐
- OneFlow 的 Global Tensor 学习笔记和实习总结
- 苹果表主题图片爬取!
- 500错误,提交响应后无法转发
- C language character classification and conversion
- Wechat H5 payment (reporting cross domain issues)
- Delphi automatically adapts to the screen size
- Friends don't see how to add, write it down first.
- 二十八.内置模块
- Use ordinary modem to make dial-up response. It was originally written in millionaire and summarized
- Flink 细粒度资源管理新特性解读
猜你喜欢

7、Request_ Response

Driverless virtual simulation (14) -- traffic sign recognition in image processing 2

【今晚七点】metaRTC的发展和应用场景探讨

Unmanned virtual simulation (XV) -- obstacle detection and recognition 1

Ros2 learning notes (6) -- customized messages and services, control instruction optimization and online map change

二十五.模块/内置模块/模块的安装
![[7:00 pm tonight] discussion on the development and application scenarios of metartc](/img/58/965e9bd295e34c4b37cd00aada2120.jpg)
[7:00 pm tonight] discussion on the development and application scenarios of metartc

Detailed explanation of basic properties of binary sort tree

Word input formula shortcut key

MySQL allows you to use the same table multiple times in a select statement
随机推荐
Open a new space for development with digital "key"
Built in functions 123
Sword finger offer special breakthrough version 92, flipped characters
Performance test and comparison of oceanbase and MariaDB using dbt-3
[NCTF2019]Fake XML cookbook
Ros2 learning notes (III) -- collect and release images of virtual simulation environment
二十七.包(import)
7、Request_Response
Flutter04-Widget初体验
使用 DBT-3 对 OceanBase 和 MariaDB 进行性能测试对比
Extraction method of code reconstruction
Playing with ABP framework -- translating mastering ABP framework
苹果表主题图片爬取!
When encountering a strange problem, start both local and remote transactions at the same time. The remote transaction is SQL2000. It is sql2008. No error is reported, but the data cannot be written
Alipay H5 page payment
Day12 job
使用Xamarin编写一个精美的APP登录注册界面
Creation of circular linked list and controllable output
【Laravel系列4.7】连接redis以及缓存应用
golang依赖注入wire使用 执行wire命令时报错:bash: wire: command not found