All concepts are based on “ User center ” Give an example .
Voice over : This is a user registration , Sign in , Common business of information query and modification .
One , Single library architecture
Single library architecture , Is the most common database architecture in the early stage of business .
*
user-service: User center services , Friendly to the caller RPC Interface
*
user-db: A library for data storage
Two , Group structure
Database grouping architecture , That is, the most common one master and many slaves , Master slave synchronization , Read write separation database architecture :
*
user-service: Still a user center service
*
user-db-M(master): Main library , Provide database write service
*
user-db-S(slave): Slave Library , Provide database reading service
The database cluster composed of master and slave is called “ a set ”.
Database clusters in the same group :
*
Passing between master and slave binlog Data synchronization
*
Multiple instance databases have the same structure
*
The data stored in multiple instances is the same , Essentially, data replication
What problems does the database grouping architecture solve ?
Most Internet businesses read more and write less , Database reading is often the first performance bottleneck , If you want :
*
Linear improvement of database reading performance
*
Improve database write performance by eliminating read-write lock conflicts
*
The realization of data from redundant slave database “ Read high availability ”
You can use the grouping schema at this time , It should be noted that , In Group Architecture , The main database is still a single point .
One sentence summary , In groups “ High read / write concurrency of database ” problem , Frequently implemented architecture design .
Three , Sharding architecture
Database fragmentation architecture , It's the most common level of segmentation (sharding):
*
user-service: Still a user center service
*
user-db1: Horizontal division 2 The first of
*
user-db2: Horizontal division 2 Second of
After slicing , Multiple database instances will also form a database cluster .
horizontal partitioning , Is it a sub database or a sub table ?
It is strongly recommended that the sub Treasury , because :
*
Sub tables still share a database file , There are still disks IO Competition of
*
Sub databases can easily migrate data to different database instances , Even on the database machine , Better scalability
Voice over : Of course , After sub Treasury , More database connections .
How to do horizontal segmentation ?
The common method is “ Range method ” and “ Hashfa ”:
Scope as above , Business primary key in user center uid Based on Division , Split the data level into two database instances .
The hash method is as follows , It is also the business primary key of user center uid Based on Division , Split the data level into two database instances .
Voice over : In this case, the hash algorithm is “ Take die ”.
Hash method in Internet database architecture , Widely used .
Sharding architecture , Segments in the same cluster :
*
There is no direct connection between multiple instances , It's not like there's a master-slave relationship binlog synchronization
*
Multiple instance database structure , It's exactly the same
*
There is no intersection between data stored by multiple instances , Data union among all instances constitutes global data
What is the solution of fragmentation architecture ?
Most Internet services have a large amount of data , Single library capacity is easy to become a bottleneck , In this case, by slicing :
*
Linear improvement of database write performance , It should be noted that , Grouping architecture can't improve database write performance linearly
*
Reduce single database data capacity
One sentence summary , The solution of fragmentation is “ Large amount of database data ” problem , Frequently implemented architecture design .
Four , Grouping + Sharding architecture
If the read-write concurrency of business is high , There's a lot of data , Grouping is usually required + Sharded database architecture :
*
Reduce the amount of data in a single database by slicing , Linear improvement of database write performance
*
Improve the read performance of database by grouping , Ensure high availability of read Library
Voice over : Most of the real architecture Online , It's like this .
Five , vertical partitioning
Database vertical segmentation , It is also a kind of common database architecture design , Vertical segmentation is generally closely combined with business .
Take user center as an example , You can do vertical segmentation like this :
User_Base(uid, uname, passwd, sex, age, …)
User_EX(uid, intro, sign, …)
*
Vertical cut apart table , All primary keys are uid
*
Login name , Password , Gender , Attributes such as age are placed in a vertical table ( library ) in
*
introduce oneself to , Attributes such as personal signature are placed in another vertical table ( library ) in
How to do vertical segmentation ?
Vertical segmentation of data based on business , Generally, attribute “ length ” and “ access frequency ” Two factors :
*
Short length , Put together those with high access frequency
*
Longer length , Lower frequency of visits put together
that is because , The database will be (row) In units , Will count load To memory (buffer) in , In the case of limited memory capacity , Properties with short length and high access frequency , Memory can load More data , More hits , disk IO Will decrease , Database performance will improve .
There are some similarities between vertical and horizontal cuts , It's different :
*
There is no direct connection between multiple instances , I.e. no binlog synchronization
*
Multiple instance database structure , It's not the same
*
There is at least one column intersection between data stored by multiple instances , Generally speaking, it is a business primary key , Data union among all instances constitutes global data
What problems can vertical segmentation solve ?
Vertical segmentation can reduce the amount of data in a single database , You can also lower the disk IO To improve throughput , But it is closely integrated with the business , Not all businesses are capable of vertical segmentation .
The article is long , A brief summary :
*
Single warehouse for initial business
*
High reading pressure , Read high availability , Group with
*
Large amount of data , Write linear expansion , Use slice
*
Short attribute , Frequently accessed properties , Split vertically together
Technology
Daily Recommendation