Talking about how to choose vertical segmentation and horizontal segmentation in the separation of reading and writing sub-databases and tables

Vertical segmentation:
1. The characteristics of vertical segmentation
  1.1 According to business segmentation, different businesses are segmented into different libraries, such as order library, user library, and commodity library.
  1.2 This method of segmentation will cause problems and cannot be joined because of cross-database situations, which will seriously reduce system performance.
 2. Advantages of
  vertical segmentation:2.1 After vertical segmentation, the business is clear, and the splitting rules are very clear. That is, different business systems correspond to different databases.
  2.2 The scalability between systems is better, the coupling degree is relatively low, and it is easier to integrate.
  2.3 Data maintenance is simple.
 3. Disadvantages of vertical segmentation
  3.1 Part of business tables cannot use join related queries, and can only increase the complexity of the system through interface calls.
  3.2 Cross-database transactions are difficult to handle. For example, production orders, deduction of inventory, once one of them fails, the entire roll back. (Need to use distributed transactions to solve)
  3.3 After vertical segmentation, facing high concurrency scenarios, there will still be a single performance bottleneck problem.


Horizontal segmentation:
1. The characteristics of horizontal segmentation
 1.1 The data of a table is divided into different databases according to certain rules.
 1.2 Need to specify a fragmentation rule.
 1.3 When querying using fragmented fields, you can determine which entity database is queried, and query all tables for other fields.
2. The advantages of horizontal segmentation.
 2.1 Solved the performance problem of the single database.
 2.2 The splitting rules are well encapsulated and almost transparent to the application side, and developers hardly need to care about splitting details.
 2.3 Improved system stability and load capacity, which is equivalent to using multiple libraries to carry the load pressure of the overall system.
3. Disadvantages of horizontal segmentation
 3.1 Splitting rules are difficult to abstract, and different query rules for the same set of business data are likely to conflict. For example, if the user table is split, it is difficult to distinguish between user query and merchant query. When merchants query orders at this time, they need to find all orders from multiple decentralized databases.
 3.2 Transaction consistency is difficult to solve. (Distributed transaction, generally based on MQ to realize distributed transaction)
 3.3 During the second expansion, data migration is very difficult, and maintenance is difficult and costly.

Guess you like

Origin blog.csdn.net/weixin_38305866/article/details/109308717