Mastering TCC Distributed Transactions: A Practical Guide to TRY, CONFIRM, and CANCEL

This article introduces the TCC (Try‑Confirm‑Cancel) distributed transaction model, explains its three phases with real‑world e‑commerce examples, compares it to other solutions, and shows how mature frameworks ensure eventual consistency and automatic rollback in failure scenarios.

Programmer DD
Programmer DD
Programmer DD
Mastering TCC Distributed Transactions: A Practical Guide to TRY, CONFIRM, and CANCEL

Distributed development inevitably encounters distributed transactions. This article walks through common solutions—Maximum Effort Notification, Reliable Message Consistency, and TCC—focusing on the TCC approach.

Maximum Effort Notification Transaction

Reliable Message Consistency Transaction

TCC Transaction

The TCC (Try‑Confirm‑Cancel) model, proposed by Alipay, is a flexible 2‑PC‑like solution widely adopted in practice.

In the typical scenario, a primary service calls two downstream services, each operating on separate databases. All calls must succeed together; if any fails, the whole transaction rolls back.

TRY Phase

The TRY phase reserves resources and sets provisional states, such as freezing inventory or pre‑adding points, without committing final changes. For example, an order service creates an order, freezes the required inventory, and marks the order status as DEALING , a temporary state indicating the transaction is in progress.

Similarly, the points service records a pending increase, and the shipping service creates a provisional shipment record, both marked as DEALING . These provisional actions constitute the TRY stage.

CONFIRM Phase

After all TRY operations succeed, the CONFIRM phase finalizes the transaction: the order status becomes paid, frozen inventory is permanently deducted, points are added, and the shipment is marked as shipped. Open‑source frameworks like ByteTCC or tcc‑transaction provide transaction managers that detect successful TRY outcomes and trigger CONFIRM logic across services.

CANCEL Phase

If any TRY operation fails, the CANCEL phase rolls back all provisional changes: the order status reverts to payment failure, frozen inventory is released, pending points are removed, and the shipment is cancelled. The TCC framework coordinates these rollbacks to ensure all services either commit or abort together.

Mature TCC implementations persist activity logs and run periodic retries, guaranteeing eventual consistency even after service crashes.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

distributed-transactiontcctransaction-management
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.