Shardingsphere x Seata, a more consistent distributed database middleware


Recently, shardingsphere, a distributed database middleware, has integrated the distributed transaction capabilities of Seata to create a more consistent distributed database middleware.


In the field of database, the implementation of distributed transaction mainly includes two phases: Xa and base flexible transaction. Xa transaction bottom layer depends on the support of specific database vendors for XA two-phase commit protocol. Generally, XA protocol guarantees the acid of distributed transaction by 2PL (two-phase lock) in prepare and commit phase, which is suitable for short transaction and non cloud environment (in cloud environment, one IO operation will take about 20ms, and two-phase lock will lock resources for 40ms, so the TPS of transactions on hot lines will be reduced to about 25 / s, while in non cloud environment, only one IO is required A few milliseconds, so the time to lock hotspot data is relatively low).

However, in terms of base flexible transactions, the SPI provided by shardingsphere for accessing distributed transactions is only applicable to services with high performance requirements and low consistency requirements.

The at pattern of the Seata core is suitable for building a relational database that supports local acid transactions. By integrating Seata, its at mode supports RC isolation level through TC global lock on the basis of one-stage commit + compensation, which can improve the consistency of shardingsphere’s distributed transactions.

Integration scheme

When integrating Seata at transactions, we need to integrate TM, RM, TC models into the SPI ecosystem of shardingsphere distributed transactions. On the database resource, Seata connects the datasource interface so that JDBC operations can communicate with TC RPC. Similarly, shardingsphere also aggregates the physical datasource configured by the user for the datasource interface. Therefore, after the physical datasource is wrapped as the datasource of Seata, Seata at transaction can be integrated into shardingsphere partition.

In the Seata model, the context of the global transaction is stored in the thread variable. By extending the transport between services, the transfer of the thread variable can be completed. The branch transaction judges whether to join the whole Seata global transaction through the thread variable. Shardingsphere’s sharding execution engine is usually executed by multiple threads. Therefore, when integrating Seata at transactions, it is necessary to extend the transaction context transfer between the main thread and the sub thread, which is exactly the same as the context transfer between services.

Shardingsphere x Seata, a more consistent distributed database middleware

Quick Start

Shardingsphere has implemented base sea TA raw JDBC example. You can try it yourself:…

Operation manual:

1. Follow the steps in sea TA work shop to download and start sea TA server.…

Refer to step6 and STEP7.

2. Execute the resources / SQL / undo log.sql script in each partition database instance to create the undo log table


About shardingsphere

Shardingsphere is an open-source ecosystem of distributed database middleware solutions. It is composed of sharding JDBC, sharding proxy and sharding sidecar (planned), which are mutually independent products. It provides standardized data fragmentation, distributed transaction and database governance functions, and can be applied to Java isomorphism, heterogeneous languages, containers, cloud native, etc Various application scenarios. At present, it has more than 8000 stars and 57 contributors.

About Seata

Seata is a distributed transaction middleware jointly open-source by Alibaba and ant financial, which integrates the accumulation of both parties in the distributed transaction technology, and precipitates rich practical experience in the new retail, cloud computing and new finance scenarios, so as to solve the distributed transaction problems faced in the microservice scenario in an efficient and invasive way. At present, it has more than 9900 stars and 83 contributors.

Shardingsphere x Seata, a more consistent distributed database middleware

Recommended Today

Modify user information changeinfo

When judging the persistence layer: Problem: there is such a problem when modifying user information. For example: the user’s email is not required. It was not empty originally. At this time, the user deletes the mailbox information and submits it. At this time, if it is not empty to judge whether it needs to be […]