当前位置:网站首页>2: Why read write separation

2: Why read write separation

2022-07-28 06:05:00 Performer

1: Why should the database be read and write separated

The systematic application of Internet is a   Read more and write less Application , For example, in the e-commerce system , The number of product browsing is more than that of placing an order . The bearing pressure of the database is high , Mainly caused by these read requests , So can we separate the read operation from the write operation , Let all read requests fall on the database dedicated to reading , All write operations fall into the database specially responsible for writing , The data from the write library is synchronized to the read Library , This ensures that all data modifications can be read , Get... From the reading library , The architecture of the system is shown in the figure :

  If the system has more read requests , Several more readers can be deployed , In this way, the read requests can be shared equally among multiple read Libraries , Reduce the pressure on each library . But when writing data , The data should fall in a certain , And the only write library . Above picture , Our writing library has only one , Of course you can deploy multiple write Libraries , But how to segment data is a very important problem , At present, only one write library is taken as an example , such as : When the merchant publishes goods , Put the data of this commodity on the write library , meanwhile , The write library synchronizes this data to two read Libraries , When buyers browse goods on the website , The commodity data will be read from the reading library , As for which library to fetch data from , It depends on the current routing of this request .

2: Advantages and disadvantages of read-write separation

advantage :

  • Split a large number of read operations from the database , Let the read operation read data from a dedicated read database , It greatly relieves the access pressure of the database , It also greatly improves the response speed of data .

shortcoming :

  • Data is written from to the database , To fetch from the database , The read-write separation architecture has one more synchronous operation , What is the operation time of synchronization , If the delay is too large, will it affect the system , What if the synchronization hangs ? for example : Order list page of e-commerce personal Center , The function is very simple , Just get the order data , Just show it on the page , But when you do it , Orders and order related data are retrieved from the reading library , This includes payment status , This user sensitive field . At a certain time of day , Suddenly received a large number of complaints from users , Said the user had paid , But the status of the order is still unpaid , Go to the database to query , It is found that the order status is unpaid , No problem . For the sake of insurance , Go to the warehouse and check this order , It is found that the order status of writing library is indeed paid , This is over. , The data extracted from the write library and the read library are inconsistent , The root of the problem is     Synch hung up
  • When synchronization hangs up , Or when the synchronization delay is relatively large , The data of write library and read library are inconsistent , This data is inconsistent , Whether the user can accept , Of course, the inconsistency of order payment status is unacceptable , Can other business scenarios be accepted ? This requires specific analysis of different business scenarios

3: Applicable scenarios of read-write separation

Some business scenarios that do not require high real-time data , Consider using read-write separation . However, scenes that require high real-time data , For example, order payment status , It is still not recommended to use read-write separation , Or when you're writing a program , Read data honestly from the write library , If you do data synchronization , Your network latency should be 5ms within , This requires a very high network environment , As you can ping Check out other machines in your network , See if you can meet this standard , If your network environment is good , Meet the requirements , Then there is no problem using read-write separation , The data is synchronized to the library in almost real time , No delay at all .

Separation of reading and writing , When you use it , We should start from the business , See if your business is suitable for using read-write separation , Each technology architecture has its own advantages and disadvantages , No good , Only suitable or not , Only an architecture suitable for business is a good architecture

 

 

原网站

版权声明
本文为[Performer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280517550501.html