Sharding is a direct way to address the limits of database storage capacity. Shards include both vertical and horizontal shards.
Vertical shards
Vertical fragmentation is also called vertical segmentation, that is, in logical tables, the original database is cut into multiple databases. After slicing, different tables are stored on different databases.
Vertical sharding is closely linked to business architecture design. For example, from the business domain of the system architecture optimization, divided into a number of sub-business systems, sub-business system coupling is low. Communication and data exchange between sub-business systems by means of interface.
The business is clear after vertical splitting, the splitting rules are clear, and the system is easy to integrate and expand. Typically used for database upper-level architecture design.
Figure 1 Vertical sharding
Horizontal sharding
Horizontal sharding is called horizontal segmentation, that is, the data rows in the logical table are recorded as units, the original logical database is divided into multiple physical database shards, the table data record distribution is stored on each shard.
Horizontal sharding mainly uses the business architecture cannot continue to subdivide, but in the database the single table data quantity is too big, the query performance degrades the scene. Through horizontal sharding, it solves the problem of single-library capacity and improves concurrent query performance.
Figure 2 horizontal shards
DDM enables automatic horizontal sharding, where the application does not need to be concerned about which piece of data is stored on the Shard.
The level of the logical table is required according to a certain shard rules, such as an order tracking system, we select the order number (ORDERID) as a split key, respectively, "Order Flow table", "Order Details table" and "Logistics tracking table" horizontal split, split rules for the key value hash after the mold, The Shard calculation rule is as follows:
H (Key (OrderId)) = Hash (Key (OrderId))%N
where n denotes a total of n data shards, H (Key (OrderId)) represents the Shard number that the order is stored after the order number is hashed and modulo is evaluated.
Figure 3 data storage after fragmentation
The above is the distributed database middleware implementation of the principle of the sub-list of the introduction, want to know more, welcome to open the distributed database Middleware DDM Home View, you can also pay attention to the public number: middleware small brother, get more information.
Recommended activities: 5-minute play micro-service
Https://activity.huaweicloud.com/cse/index.html?dfk
Introduction to the implementation principle of distributed database Middleware one: Sub-Library sub-table