当前位置:网站首页>Summary of solutions to cross system data consistency problems
Summary of solutions to cross system data consistency problems
2022-06-27 23:14:00 【The way to improve the structure】
1、 Why is there a problem of cross system data consistency ?

2、 Analysis of the difficulties of consistency problem
Suppose there is an order system and an inventory system , In actual business, the creation of orders will be accompanied by the reduction of inventory . The two systems are deployed for microservice , Its application data is also stored in an independent database , The two systems communicate through the network .

2.1 CAP principle

give up A ( Usability ) To protect CP Specifically, after a communication failure occurs , The application will go into a blocking state , Try to resume communication with the inventory system until all data processing is completed . This scheme gives priority to data integrity , But the user experience of this scheme is very poor , Because the user will be waiting until all operations are completed .
CA Because partition tolerance is not considered , So all its operations need to be completed in the same process ( That is what we often call monomer application ); AP Because of the abandonment of data consistency , It is suitable for projects with low data requirements but emphasizing user experience , Such as blog 、 News, etc ; CP Instead, you give up availability , It is suitable for trading systems with high data requirements , Such as bank transactions 、 E-commerce order transactions, etc , Even if the user waits for a long time , It is also necessary to ensure the integrity and reliability of data .
such as , Transactions between one database and multiple databases XA Transaction performance may differ 10 times . in addition , stay XA In the process of transaction processing, it will occupy lock resources for a long time , So we didn't consider this plan at first .
2.2 TCC Consistency program
Try Interface is used to check data 、 Reserve business resources . Confirm The interface is used to confirm the actual business operation 、 Update business resources . Cancel An interface is a release Try Resources reserved in the interface .
1、Try Is the first stage , Used to try and lock resources ; 2、 If the resource is locked successfully , The second stage begins Confirm Submit to complete data operation ; 3、 If the resource lock fails , The second stage will proceed Cancel Roll back data ;
Put most of the business logic in Try Stages to complete , because TCC At the beginning of the design Confirm or Cancel It must be successful , So don't include any business code or remote communication in the second phase , Release frozen resources only through the simplest code .
If Confirm or Cancel An error occurred while executing , The specific application will also try to retry the execution to ensure successful execution , This process may be performed many times update sentence , So pay attention to the idempotency of the code .
Under the minimum probability ,Confim or Cancel Failed after multiple retries , The data will eventually be inconsistent , This requires the development of additional data integrity verification procedures to remedy or manual supplementary recording .
stay Java Famous in the open source field TCC Framework has :ByteTCC、Hmily、Tcc-transaction And Seata.
3、 Practice of effective data synchronization scheme
3.1 Real time synchronization
3.1.1 Database level
Expand the load capacity of the database horizontally . Fault tolerance , High availability ,Failover( Failed to switch )/High Availability The data backup .

When the slave node connects to the master node , The master node creates a log dump Threads , Used for sending binlog The content of . In the reading binlog Operating time , This thread will change the binlog Lock , When the read is complete , Before sending to the slave , The lock will be released .
When executed from a node start slave After the command , From the node, a I/O Threads are used to connect to the master node , Request the updated binlog.I/O Thread received master binlog dump After the update from the process , Keep it locally relay-log( relay logs ) in .
SQL The thread is responsible for reading relay log The content in , Parse into specific operations and execute , Finally, ensure the consistency of master-slave data .
3.1.2 API call

3.2 Asynchronous synchronization
3.2.1 Asynchronous message queuing

3.2.2 Timing synchronization
4、 Application experience summary
Any data synchronization has no advantages or disadvantages , Have their own suitable application scenarios .
Architecture solutions to current problems , At the same time, it is easy to expand and maintain , That is an excellent architecture .
I hope today's explanation will be helpful to you , thank you !
Thanks for reading
Adhere to the original and share valuable dry goods technical articles !
Official account , Free learning materials
If you think it's good , Welcome to follow and forward ~

This article is from WeChat official account. - The road to the advanced architecture (jiagou_jingjin).
If there is any infringement , Please contact the [email protected] Delete .
Participation of this paper “OSC Source creation plan ”, You are welcome to join us , share .
边栏推荐
- Spark BUG实践(包含的BUG:ClassCastException;ConnectException;NoClassDefFoundError;RuntimeExceptio等。。。。)
- netERR_ CONNECTION_ Refused solution
- Kill the general and seize the "pointer" (Part 2)
- MySQL十八:写语句的执行过程
- "Top stream Aidou manufacturing machine" cooperates with four industrial capitals to become LP
- Service gateway of microservices
- Redis principle - string
- Structured machine learning project (II) - machine learning strategy (2)
- netERR_CONNECTION_REFUSED 解决大全
- [js]var, let, const
猜你喜欢

量化交易入门教程

Consumer finance app user insight in the first quarter of 2022 - a total of 44.79 million people

How to participate in openharmony code contribution

居家办公竟比去公司上班还累?

打造南沙“强芯”,南沙首届IC Nansha大会召开

Spark BUG實踐(包含的BUG:ClassCastException;ConnectException;NoClassDefFoundError;RuntimeExceptio等。。。。)

First knowledge of the second bullet of C language

Liuleifeng, a "good man in Guangzhou" in the first quarter of 2022, has a strong sense of integrity and food safety

资深猎头团队管理者:面试3000顾问,总结组织出8大共性(茅生)

Structured machine learning project (II) - machine learning strategy (2)
随机推荐
Common APIs (Methods) for scope -number and string
向量召回和字面召回的选择与权衡
This kind of people began to be robbed by VC with a monthly salary of 80000 yuan
云辅助隐私集合求交(Server-Aided PSI)协议介绍:学习
Use logrotate to automatically cut the website logs of the pagoda
广告太「野」,吉野家「渡劫」
Spark BUG实践(包含的BUG:ClassCastException;ConnectException;NoClassDefFoundError;RuntimeExceptio等。。。。)
元气森林的5元有矿之死
基于 ESXi 的黑群晖 DSM 7.0.1 安装 VMware Tools
Zabbix6.0升级指南-数据库如何同步升级?
PE buys a underwear company
陈云pytorch学习笔记_用50行代码搭建ResNet
如何设置企业微信群机器人定时发消息?
因美纳陷数据泄露“丑闻”:我国基因数据安全能交给美企吗?
Crawler notes (1) - urllib
微服务之服务网关
Livox Lidar+海康Camera 基于loam的实时三维重建生成RGB彩色点云
Memoirs of actual combat: breaking the border from webshell
Improving deep neural networks: hyperparametric debugging, regularization and optimization (III) - hyperparametric debugging, batch regularization and program framework
EasyCVR平台路由日志功能的技术实现过程【附代码】