当前位置:网站首页>Introduction to distributed transactions
Introduction to distributed transactions
2022-07-07 05:41:00 【Qin Tian】
Catalog
One 、 Distributed transaction concept
4、 Distributed transaction generation scenario
Two 、 Basic theory of distributed transaction
One 、 Distributed transaction concept
1、 What is business
Business can be seen as a big activity , It's made up of different little activities , These activities are either all successful , All or nothing .
2、 Local transactions
Four features of database transaction ACID:
- A(Atomic): Atomicity , All operations that make up a transaction , Or it's all done , Or none at all , Partial success and partial failure are not possible .
- C(Consistency): Uniformity , Before and after transaction execution , The consistency constraint of the database is not broken . such as : Zhang San turns to Li Si 100 element , The data before and after transfer is in correct status, which is called consistency , If Zhang San turns out 100 element , Li Si's account didn't increase 100 This leads to a data error , There is no consistency .
- I(Isolation): Isolation, , Transactions in a database are usually concurrent , Isolation means that the execution of two concurrent transactions does not interfere with each other , One transaction cannot see the intermediate state of other transaction running processes . Dirty reading can be avoided by configuring transaction isolation level 、 Repeat reading and so on .
- D(Durability): persistence , After the transaction completes , Changes to data from this transaction are persisted to the database , And will not be rolled back .
When database transaction is implemented, all operations involved in a transaction will be incorporated into an indivisible execution unit , All operations in the execution unit are either successful , Or they all failed , As long as any of these operations fail , Will cause the entire transaction to roll back .
3、 Distributed transactions
The distributed system will split an application system into multiple services that can be deployed independently , Therefore, remote cooperation between services is needed to complete transaction operations , In this kind of distributed system environment, different services cooperate with each other remotely through the network to complete the transaction, which is called distributed transaction , For example, users register to send points transaction 、 Create order inventory reduction transaction , Bank transfer transactions are distributed transactions .
4、 Distributed transaction generation scenario
- The typical scenario is microservice architecture , Between microservices The remote call completes the transaction operation . such as : Order and inventory microservices , When placing an order, the order micro service requests the inventory micro service to reduce the inventory . in short : Span JVM Process generates distributed transaction .
- A single system accesses multiple database instances , Generate distributed transactions across database instances .
- Multiple services access the same database instance , such as : Order and inventory microservices generate distributed transactions even if they access the same database , The reason is that Span JVM process , The two microservices hold different database links for database operation , A distributed transaction is generated .
Two 、 Basic theory of distributed transaction
1、CAP theory
1) Concept
CAP yes Consistency、Availability、Partition tolerance Abbreviations of three words , They mean consistency 、 Usability 、 Zone tolerance .

2) combination
In all distributed transaction scenarios, there will be no CAP Three characteristics , Because I have P Under the premise of C and A Can't coexist .
- AP: Give up consistency , The pursuit of partition tolerance and usability . This is the choice of many distributed systems when they are designed .Eureka Cluster is adopted AP design idea .
- CP: Discard availability , Pursue consistency and partition fault tolerance .zookeeper colony .
- CA: Give up zoning tolerance , That is to say, there is no partition , Don't consider the problem of network failure or node hang up , You can achieve consistency and availability . Then the system will not be a standard distributed system , Our most commonly used relational data is enough CA.
3) summary
CAP It's a proven theory : A distributed system can only satisfy at most Uniformity (Consistency)、 Usability (Availability) And zone tolerance (Partition tolerance) Two of these three .
It can be used as our architecture design 、 Consideration criteria for technology selection . For most large Internet application scenarios , There are many nodes 、 Deployment is decentralized , And now the scale of the cluster is growing , So node failure 、 Network failure is the norm , And make sure the service availability reaches N individual 9(99.99..%), And to achieve good response performance to improve the user experience , Therefore, the following choices are generally made : Guarantee P and A, Abandon C Strong consistency , Ensure ultimate consistency .
2、BASE theory
1) Strong consistency and final consistency
- Strong consistency :CAP Consistency in requires that each node data must be consistent at any time when queried , It emphasizes strong consistency .
- Weak consistency : After the data is updated successfully , The system does not promise to read the latest written value immediately , I don't promise how long it will take to read .
- Final consistency : Allow yes In a period of time, the data of each node is inconsistent , But after a period of time, the data of each node must be consistent , It emphasizes Consistency of final data .
2) Concept
BASE yes Basically Available( Basic available )、Soft state( Soft state ) and Eventually consistent ( Final consistency ) Abbreviations of three phrases .
BASE The theory is right CAP in AP An extension of , Get availability by sacrificing strong consistency , In case of failure, it is allowed that some parts are not available but the core functions shall be available , Allow data to be inconsistent over time , But in the end it's consistent .
Satisfy BASE Theoretical business , We call it “ Flexible business ”.
- Basic available : When a distributed system fails , Allow the loss of some available functions , Make sure the core functions are available . Such as , There is something wrong with the payment of e-commerce website transactions , Products can still be viewed normally .
- Soft state : Because don't ask for strong consistency , therefore BASE Allow in system There is an intermediate state ( It's also called soft state ), This state does not affect system availability , As of the order “ In the payment ”、“ Data synchronization ” Equal state , After the data is finally consistent, the status changes to “ success ” state .
- Final consistency : Final agreement means After a period of time , All node data will be consistent . As of the order " In the payment " state , In the end, it will become “ Successful payment ” perhaps " Failure to pay ", Agree the order status with the actual transaction result , But it takes a certain delay 、 wait for .
边栏推荐
- 5. 数据访问 - EntityFramework集成
- The year of the tiger is coming. Come and make a wish. I heard that the wish will come true
- When deleting a file, the prompt "the length of the source file name is greater than the length supported by the system" cannot be deleted. Solution
- 纪念下,我从CSDN搬家到博客园啦!
- Design, configuration and points for attention of network specified source multicast (SSM) simulation using OPNET
- Under the trend of Micah, orebo and apple homekit, how does zhiting stand out?
- 论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
- Reading the paper [sensor enlarged egocentric video captioning with dynamic modal attention]
- 分布式事务介绍
- Paper reading [open book video captioning with retrieve copy generate network]
猜你喜欢

Unity keeps the camera behind and above the player

Preliminary practice of niuke.com (9)
![[JS component] date display.](/img/26/9bfc752c8c9a933a8e33b59e0488a2.jpg)
[JS component] date display.

什么是消息队列?

消息队列:消息积压如何处理?

随机生成session_id

京东商品详情页API接口、京东商品销量API接口、京东商品列表API接口、京东APP详情API接口、京东详情API接口,京东SKU信息接口

Jhok-zbl1 leakage relay

C#可空类型
![[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training](/img/d6/e6db0d76e81e49a83a30f8c1832f09.png)
[论文阅读] Semi-supervised Left Atrium Segmentation with Mutual Consistency Training
随机推荐
论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
分布式事务解决方案之TCC
张平安:加快云上数字创新,共建产业智慧生态
淘宝店铺发布API接口(新),淘宝oAuth2.0店铺商品API接口,淘宝商品发布API接口,淘宝商品上架API接口,一整套发布上架店铺接口对接分享
Batch size setting skills
集群、分布式、微服务的区别和介绍
DOM node object + time node comprehensive case
In memory, I moved from CSDN to blog park!
高级程序员必知必会,一文详解MySQL主从同步原理,推荐收藏
JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
The 2022 China low / no code Market Research and model selection evaluation report was released
Two person game based on bevy game engine and FPGA
How does mapbox switch markup languages?
Taobao commodity details page API interface, Taobao commodity list API interface, Taobao commodity sales API interface, Taobao app details API interface, Taobao details API interface
Writing process of the first paper
Educational Codeforces Round 22 B. The Golden Age
Paper reading [semantic tag enlarged xlnv model for video captioning]
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
Leakage relay jelr-250fg