1.1 transactions

I don’t know if you have come across such a situation, go to a small shop to buy something, pay for it, but the shopkeeper is dealing with some other things, forget you paid for it, and ask you to pay again.

Or I was told that no transaction had taken place when I had already been charged for online purchases. All of these situations are caused by the absence of transactions. This illustrates something about the importance of transactions in life.

Have business, you go to the shop to buy things, that is to hand over money and hand delivery. With the transaction, you go online shopping, deducting money to generate order transactions.

1.2 Specific definition of transactions

Transactions provide a mechanism to bring all operations involved in an activity into one indivisible unit of execution. All operations that make up a transaction can be committed only if all operations are properly executed. Failure of any operation will result in a rollback of the entire transaction.

Simply put, transactions provide an “All or Nothing” mechanism.

1.3 What are distributed transactions

Distributed transaction refers to participant in the transaction, support transaction server, the server resources and transaction manager respectively in different on different nodes of a distributed system that, in short, is a major operation is composed of different small operation, these small operation distribution on different servers, and belong to different application, Distributed transactions require that these small operations either all succeed or all fail. Essentially, distributed transactions are designed to ensure data consistency across different databases.

1.4 Causes of distributed transactions

Database sub - database sub - tableCopy the code

When the database single table a year to produce more than 1000W data, then it is necessary to consider the sub-database sub-table, the specific sub-database sub-table principle is not explained here, later free to say in detail, simply speaking is the original a database into a number of databases. In this case, if an operation accesses both 01 and 02 libraries and the data is consistent, then distributed transactions are used.

Application of SOA,Copy the code

Soa-ization is the servitization of business. For example, the original single support of the entire e-commerce website, now the whole website is disassembled, separated from the order center, user center, inventory center. For the order center, there is a special database to store the order information, the user center also has a special database to store the user information, and the inventory center also has a special database to store the inventory information. At this time, if you want to operate the order and inventory at the same time, it will involve the order database and inventory database, in order to ensure data consistency, it needs to use distributed transactions.

2.1 Distributed Transaction Solution – Two-phase commit protocol 2PC

The first stage is the voting stage, in which all participants give feedback on the success of the transaction to the coordinator.

The second phase is the implementation phase, where the coordinator, based on the feedback of all participants, notifies all participants and synchronously commits or rolls back on all branches.

2.2 Distributed Transaction Solution – Compensation transaction solution TCC

TCC schemes have been widely implemented in the fields of e-commerce and finance. The TCC solution is an improvement on the two-phase commit, which explicitly divides each branch of the business logic into three operations: Try, Confirm, and Cancel. The Try part completes the business preparation, the Confirm part completes the business submission, and the Cancel part completes the transaction rollback. The basic principle is shown in the figure below.

We only cover these two solutions, but there are many more….. Because Seata’s AT mode is based on 2PC commits, Seata’s TCC mode is the same as the compensation transaction scheme TCC scheme.

3.1 Distributed transaction framework -Seata

Seata is an open source distributed transaction framework. Dedicated to providing high performance and easy to use distributed transaction services under the microservices architecture. Before the open source of Seata, the internal version of Seata has been playing the role of distributed consistency middleware in Ali economy, helping the economy to smoothly go through the Double 11 of each year and providing strong support for the business of each business unit. After years of precipitation and accumulation, commercial products have been sold on Ali Cloud and Financial cloud. In order to create a more complete technology ecosystem and inclusive technology achievements, Seata officially announced open source. In the future, Seata will help its technology in the form of community construction more reliable and complete

Seata source code:github.com/seata/seata

Seata currently has a very high level of usage and activity in the market based on the open source address

3.2 Seata product module

There are three modules in Seata, which are TM, RM and TC. TM and RM are integrated with the business system as clients of Seata, and TC is deployed independently as server of Seata.

TC (Transaction Coordinator) – Transaction Coordinator

Maintains the state of global and branch transactions and drives global transaction commit or rollback.

TM (Transaction Manager) – Transaction Manager

Define the scope of a global transaction: start, commit, or roll back the global transaction.

RM Resource Manager (RM) – Resource Manager

Manage resources for branch transaction processing, talk to TCS to register branch transactions and report status of branch transactions, and drive commit or rollback of branch transactions

This is just a brief introduction to distributed transactions and Seata. For a more comprehensive and in-depth introduction to Seata in action, please watch the distributed Transaction Solutions Seata webcast. If you are interested in this live broadcast, please scan the qr code below

The details of the live broadcast are as follows:

Long press scan code to lock 0 quota

Get free Seata course materials and live links!

First 50 people only, first come, first served!