Why Distributed Transactions Stall Microservices and How Alibaba’s GTS Solves It
The article examines the challenges of distributed transactions in microservice architectures, reviews traditional solutions such as XA, TCC, and message-based eventual consistency, and introduces Alibaba’s Global Transaction Service (GTS) as a high‑performance, low‑intrusion middleware with various deployment options and real‑world usage examples.
1 Microservice Development
Microservices advocate splitting a monolithic application into many simple, loosely‑coupled services, reducing development difficulty, improving scalability, and enabling agile development. Companies such as Hailo (160 services), Netflix (≈600 services), Alibaba, Tencent, 360, JD, 58.com, etc., have adopted microservice architectures. Popular frameworks include Dubbo, Spring Cloud, Thrift, gRPC.
2 Problems When Deploying Microservices
Although microservices are popular, many small‑to‑medium internet companies find implementation difficult due to limited experience and technical strength. According to architect Chris Richardson, the main challenges are:
Inter‑process communication and fault handling become more complex after splitting a monolith.
Distributed transaction issues become prominent when a single business function spans multiple services and databases.
Testing, deployment, and monitoring become harder as the number of services grows.
RPC frameworks have mitigated the first and third problems, but the second problem—distributed transactions—remains unsolved.
3 Traditional Distributed Transaction Solutions
3.1 XA Two‑Phase Commit
Transaction middleware interacts with databases via the XA interface, using a two‑phase commit protocol. The first (prepare) phase gathers participants' readiness, and the second (commit/rollback) phase executes the decision. While widely supported, XA locks resources for a long time and degrades performance, making it unsuitable for microservice transactions.
3.2 TCC (Try‑Confirm‑Cancel)
TCC improves on two‑phase commit by splitting each business branch into Try, Confirm, and Cancel operations. Try prepares, Confirm commits, and Cancel rolls back. The transaction coordinator registers the transaction, invokes try on all services, then decides to call confirm or cancel based on results. TCC reduces lock contention and improves throughput but requires strong application intrusion and complex idempotent implementations.
High intrusion: each branch must implement try, confirm, cancel.
Implementation difficulty: need to handle various failure scenarios and ensure idempotency.
3.3 Message‑Based Final Consistency
This approach uses a message broker to guarantee consistency between upstream and downstream applications. Local operations and message sending are wrapped in a single transaction; downstream services consume the message and perform their actions, achieving eventual consistency through retries.
While reducing lock time, this method also requires significant application changes.
4 GTS – Alibaba’s Distributed Transaction Solution
GTS (Global Transaction Service) is a middleware developed by Alibaba that provides a one‑stop solution for distributed transactions in microservice architectures.
4.1 Core Advantages
High performance : average branch response time ≈2 ms; a three‑node cluster can handle >30 k TPS.
Low intrusion : only an @TxcTransaction annotation is needed to declare a transaction.
Comprehensive support : works with EDAS, Dubbo, Spring Cloud, and offers an MT mode equivalent to TCC for custom behavior.
Strong fault tolerance : eliminates single‑point failure of XA coordinators and ensures strict data consistency under various exceptions.
4.2 Application Scenarios
Applicable to finance, telecom, e‑commerce, logistics, advertising, social, gaming, IoT, vehicle‑IoT, etc.
4.3 Integration with Microservices
GTS consists of a client, a resource manager, and a transaction coordinator. The client defines transaction boundaries, the RM creates, commits, or rolls back branches, and the server manages the overall transaction lifecycle.
4.4 Output Forms
Public‑cloud output (for Alibaba Cloud users).
Internet output (for non‑Alibaba‑cloud users, client deployed locally).
Private‑cloud output (deployed on customers’ own clouds).
4.4.1 Public‑Cloud Output
When the business system is already on Alibaba Cloud, GTS can be enabled directly, providing optimal network conditions and performance.
4.4.2 Internet Output
Suitable for users outside Alibaba Cloud; the client runs locally while the service runs in the cloud, still achieving >1000 TPS with 20 ms latency for a two‑branch global transaction.
4.4.3 Private‑Cloud Output
Deployed on customers’ own clouds; already used by more than ten large enterprises with strict performance and stability requirements.
4.5 Usage Method
GTS requires minimal code changes. For example, an order service using Dubbo adds the @TxcTransaction annotation to the business method, and the transaction ID (xid) is propagated automatically.
The provider side implements the corresponding update logic, as shown in the following diagram.
4.6 Production Adoption
GTS is used extensively in Alibaba’s own systems such as Taobao, Tmall, Alibaba Pictures, and 1688, handling up to 100 k TPS during peak events. Over 100 online customers across finance, logistics, retail, and shared‑mobility have adopted GTS.
4.7 Engineering Samples
Two sample projects are provided: sample-txc-simple (single‑node transaction) and sample-txc-dubbo (Dubbo‑based order‑stock scenario). They demonstrate how to set up MySQL databases, configure data sources, and run the examples.
4.7.3 SQL Definitions
CREATE TABLE txc_undo_log ( id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Primary key', gmt_create datetime NOT NULL COMMENT 'Create time', gmt_modified datetime NOT NULL COMMENT 'Modify time', xid varchar(100) NOT NULL COMMENT 'Global transaction ID', branch_id bigint(20) NOT NULL COMMENT 'Branch ID', rollback_info longblob NOT NULL COMMENT 'Log', status int(11) NOT NULL COMMENT 'Status', server varchar(32) NOT NULL COMMENT 'Branch DB IP', PRIMARY KEY (id), KEY unionkey (xid,branch_id) ) ENGINE=InnoDB AUTO_INCREMENT=211225994 DEFAULT CHARSET=utf8 COMMENT='Transaction log table'; CREATE TABLE user_money_a ( id int(11) NOT NULL AUTO_INCREMENT, money int(11) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; CREATE TABLE user_money_b ( id int(11) NOT NULL AUTO_INCREMENT, money int(11) DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; CREATE TABLE orders ( id bigint(20) NOT NULL AUTO_INCREMENT, user_id varchar(255) NOT NULL, product_id int(11) NOT NULL, number int(11) NOT NULL, gmt_create timestamp NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM AUTO_INCREMENT=351 DEFAULT CHARSET=utf8; CREATE TABLE stock ( product_id int(11) NOT NULL, price float NOT NULL, amount int(11) NOT NULL, PRIMARY KEY (product_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5 Conclusion
GTS has proven its reliability through Alibaba’s double‑11 peak traffic and now serves millions of transactions per day for a wide range of industries, offering ACID guarantees, high performance, high availability, and low application intrusion.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Developer
Alibaba's official tech channel, featuring all of its technology innovations.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
