当前位置:网站首页>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 .
边栏推荐
- First knowledge of the second bullet of C language
- 6G显卡显存不足出现CUDA Error:out of memory解决办法
- 跟着存档教程动手学RNAseq分析(四):使用DESeq2进行DE分析的QC方法
- 树莓派(以及各种派)使用指南
- Azure Kinect DK 实现三维重建 (PC非实时版)
- [electron] basic learning
- Discuz淘宝客网站模板/迪恩淘宝客购物风格商业版模板
- 【微服务】(十六)—— 分布式事务Seata
- [network] common request methods
- Improving deep neural networks: hyperparametric debugging, regularization and optimization (III) - hyperparametric debugging, batch regularization and program framework
猜你喜欢

Service gateway of microservices

Character interception triplets of data warehouse: substrb, substr, substring

第一性原理(最优解理论)

Summary of various loams (laser SLAM)

各种loam总结(激光slam)

Passerelle de service pour les microservices

mysql操作入门(四)-----数据排序(升序、降序、多字段排序)

C # QR code generation and recognition, removing white edges and any color

Death of 5 yuan youkuang in Yuanqi forest

月薪3万的狗德培训,是不是一门好生意?
随机推荐
基于 ESXi 的黑群晖 DSM 7.0.1 安装 VMware Tools
Do you know the full meaning of log4j2 configurations? Take you through all the components of log4j2
ABAP随笔-物料主数据界面增强-页签增强
Design of STM32 and rc522 simple bus card system
[electron] basic learning
居家办公竟比去公司上班还累?
Spug - 轻量级自动化运维平台
Hiplot 在線繪圖工具的本地運行/開發庫開源
First knowledge of the second bullet of C language
【蓝桥杯集训100题】scratch数字计算 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第16题
pytorch基础(1)
mysql中一对多关联,获取多表中最新一条数据
【IDEA】IDEA 格式化 代码技巧 idea 格式化 会加 <p> 标签
What problems should be paid attention to in the serpentine wiring of PCB?
Process judgment - ternary operation - for loop
ABAP essay - material master data interface enhancement - tab enhancement
移动端避免使用100vh[通俗易懂]
Spark BUG實踐(包含的BUG:ClassCastException;ConnectException;NoClassDefFoundError;RuntimeExceptio等。。。。)
Is the dog virtue training with a monthly salary of 30000 a good business?
PHP connects to database to realize user registration and login function