Convert Figma logo to code with AI

liuyangming logoByteTCC

ByteTCC is a distributed transaction manager based on the TCC(Try/Confirm/Cancel) mechanism. It’s compatible with the JTA specification. User guide: https://github.com/liuyangming/ByteTCC/wiki

2,896
913
2,896
100

Top Related Projects

10,038

A distributed transaction framework, supports workflow, saga, tcc, xa, 2-phase message, outbox patterns, supports many languages.

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.

tcc-transaction是TCC型事务java实现

Apache ServiceComb Pack is an eventually data consistency solution for micro-service applications. ServiceComb Pack currently provides TCC and Saga distributed transaction co-ordination solutions by using Alpha as a transaction coordinator and Omega as an transaction agent .

Quick Overview

ByteTCC is an open-source TCC (Try-Confirm-Cancel) transaction framework for distributed systems. It provides a simple and efficient way to manage distributed transactions across multiple microservices or databases, ensuring data consistency in complex distributed environments.

Pros

  • Lightweight and easy to integrate with existing Spring-based applications
  • Supports multiple transaction propagation scenarios, including nested transactions
  • Compatible with various databases and messaging systems
  • Provides a flexible compensation mechanism for handling transaction failures

Cons

  • Limited documentation, especially for advanced use cases
  • Primarily focused on Java-based applications, which may limit its use in polyglot environments
  • Requires careful configuration and understanding of distributed transaction concepts
  • May introduce additional complexity in simpler application architectures

Code Examples

  1. Configuring a TCC transaction:
@Compensable(
    confirmMethod = "confirmOrderCreation",
    cancelMethod = "cancelOrderCreation"
)
public void createOrder(Order order) {
    // Business logic for creating an order
}

public void confirmOrderCreation(Order order) {
    // Confirmation logic
}

public void cancelOrderCreation(Order order) {
    // Cancellation logic
}
  1. Using ByteTCC with Spring Boot:
@SpringBootApplication
@EnableTransactionManagement
@EnableTCC
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
  1. Configuring ByteTCC properties:
bytejta.transaction.recovery.recoveryEnabled=true
bytejta.transaction.recovery.recoveryInterval=30
bytejta.transaction.recovery.maxRecoveryTime=120

Getting Started

To use ByteTCC in your Spring Boot project:

  1. Add the ByteTCC dependency to your pom.xml:
<dependency>
    <groupId>org.bytesoft</groupId>
    <artifactId>bytetcc-supports-springboot</artifactId>
    <version>0.5.12</version>
</dependency>
  1. Enable TCC in your main application class:
@SpringBootApplication
@EnableTCC
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
  1. Annotate your transactional methods with @Compensable and implement the corresponding confirm and cancel methods.

  2. Configure ByteTCC properties in your application.properties file as needed.

Competitor Comparisons

10,038

A distributed transaction framework, supports workflow, saga, tcc, xa, 2-phase message, outbox patterns, supports many languages.

Pros of dtm

  • Supports multiple programming languages (Go, Java, PHP, Python, Node.js)
  • Offers various transaction modes (2PC, Saga, TCC, XA)
  • Provides a user-friendly dashboard for monitoring and management

Cons of dtm

  • Relatively newer project with less production usage
  • Documentation may not be as comprehensive as ByteTCC

Code Comparison

dtm (Go):

saga := dtmcli.NewSaga(DtmServer, gid).
    Add(busi.Busi+"/TransOut", busi.Busi+"/TransOutCompensate", &req).
    Add(busi.Busi+"/TransIn", busi.Busi+"/TransInCompensate", &req)
err := saga.Submit()

ByteTCC (Java):

@Compensable(confirmMethod = "confirmTransfer", cancelMethod = "cancelTransfer")
public void transfer(int fromId, int toId, double amount) {
    this.accountDao.updateAmount(fromId, -amount);
    this.accountDao.updateAmount(toId, amount);
}

Summary

dtm offers multi-language support and various transaction modes, making it versatile for different use cases. It also provides a dashboard for easier management. However, being a newer project, it may have less production usage and potentially less comprehensive documentation compared to ByteTCC.

ByteTCC, on the other hand, is more focused on Java applications and has been around longer, potentially offering more stability and production-tested features. Its code structure is more annotation-based, which may be familiar to Java developers working with Spring frameworks.

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.

Pros of Seata

  • More comprehensive distributed transaction solution, supporting multiple transaction modes (AT, TCC, SAGA, XA)
  • Larger community and active development, with regular updates and releases
  • Better integration with popular frameworks and cloud-native environments

Cons of Seata

  • Higher complexity and steeper learning curve due to its extensive features
  • Potentially higher resource consumption and performance overhead in some scenarios

Code Comparison

ByteTCC:

@Compensable(confirmMethod = "confirmIncrease", cancelMethod = "cancelIncrease")
public void increase() {
    // Business logic
}

Seata:

@GlobalTransactional
public void businessMethod() {
    // Business logic
}

Key Differences

  1. Transaction model: ByteTCC focuses solely on the TCC (Try-Confirm-Cancel) model, while Seata supports multiple transaction modes.
  2. Ease of use: ByteTCC has a simpler API and is easier to integrate for TCC-specific use cases, whereas Seata offers more flexibility but requires more configuration.
  3. Community support: Seata has a larger and more active community, being an Apache incubator project, which may lead to better long-term support and development.

Conclusion

Choose ByteTCC for simpler TCC-based distributed transactions with minimal overhead. Opt for Seata when requiring a more comprehensive distributed transaction solution with multiple transaction modes and broader ecosystem support.

tcc-transaction是TCC型事务java实现

Pros of tcc-transaction

  • More comprehensive documentation and examples
  • Better support for Spring Framework integration
  • Active community and regular updates

Cons of tcc-transaction

  • Steeper learning curve due to more complex architecture
  • Higher resource consumption in some scenarios
  • Less flexible in terms of customization options

Code Comparison

tcc-transaction:

@Compensable(confirmMethod = "confirmMethod", cancelMethod = "cancelMethod")
public void tryMethod(TransactionContext transactionContext) {
    // Try phase logic
}

ByteTCC:

@Compensable(confirmableKey = "service.confirm", cancellableKey = "service.cancel")
public void tryMethod() {
    // Try phase logic
}

Both projects implement the TCC (Try-Confirm-Cancel) pattern for distributed transactions, but they differ in their approach and syntax. tcc-transaction uses explicit method names for confirm and cancel phases, while ByteTCC uses key-based references.

tcc-transaction provides more built-in features and integrations, making it easier to adopt in complex enterprise environments. However, this comes at the cost of increased complexity and potential resource overhead.

ByteTCC, on the other hand, offers a simpler and more lightweight approach, which may be preferable for smaller projects or those requiring more customization. It has a gentler learning curve but may require more manual configuration in certain scenarios.

Ultimately, the choice between these two libraries depends on the specific requirements of your project, the existing technology stack, and the level of control you need over the transaction process.

Apache ServiceComb Pack is an eventually data consistency solution for micro-service applications. ServiceComb Pack currently provides TCC and Saga distributed transaction co-ordination solutions by using Alpha as a transaction coordinator and Omega as an transaction agent .

Pros of ServiceComb-Pack

  • Part of the Apache Software Foundation, ensuring long-term support and community-driven development
  • Offers multiple transaction protocols (TCC, Saga) for different use cases
  • Provides integration with popular frameworks like Spring Boot and Dubbo

Cons of ServiceComb-Pack

  • More complex setup and configuration compared to ByteTCC
  • Potentially higher learning curve due to broader feature set
  • May have higher resource overhead for simpler use cases

Code Comparison

ByteTCC example:

@Compensable(confirmMethod = "confirmIncrease", cancelMethod = "cancelIncrease")
public void increase() {
    // Business logic
}

ServiceComb-Pack example:

@Compensable(compensationMethod = "cancel")
public boolean tryIncrease() {
    // Try phase logic
}

public void cancel() {
    // Compensation logic
}

Both projects aim to provide distributed transaction management for microservices, but they differ in their approach and feature set. ByteTCC focuses specifically on the TCC (Try-Confirm-Cancel) pattern, while ServiceComb-Pack offers a broader range of transaction protocols. ByteTCC may be simpler to implement for projects that only require TCC, while ServiceComb-Pack provides more flexibility for complex distributed systems.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

 ByteTCC is an implementation of Distributed Transaction Manager, based on Try-Confirm-Cancel (TCC) mechanism.

ByteTCC is comptible with JTA and could be seamlessly integrated with Spring and other Java containers.

1. Quick Start

1.1 Add maven depenency

1.1.1. Spring Cloud
<dependency>
	<groupId>org.bytesoft</groupId>
	<artifactId>bytetcc-supports-springcloud</artifactId>
	<version>0.5.12</version>
</dependency>
1.1.2. dubbo
<dependency>
	<groupId>org.bytesoft</groupId>
	<artifactId>bytetcc-supports-dubbo</artifactId>
	<version>0.5.12</version>
</dependency>

1.2 Compose a business service

@Service("accountService")
@Compensable(
  interfaceClass = IAccountService.class 
, confirmableKey = "accountServiceConfirm"
, cancellableKey = "accountServiceCancel"
)
public class AccountServiceImpl implements IAccountService {

	@Resource(name = "jdbcTemplate")
	private JdbcTemplate jdbcTemplate;

	@Transactional
	public void increaseAmount(String accountId, double amount) throws ServiceException {
	    this.jdbcTemplate.update("update tb_account set frozen = frozen + ? where acct_id = ?", amount, acctId);
	}

}

1.3 Compose a confirm service

@Service("accountServiceConfirm")
public class AccountServiceConfirm implements IAccountService {

	@Resource(name = "jdbcTemplate")
	private JdbcTemplate jdbcTemplate;

	@Transactional
	public void increaseAmount(String accountId, double amount) throws ServiceException {
	    this.jdbcTemplate.update("update tb_account set amount = amount + ?, frozen = frozen - ? where acct_id = ?", amount, amount, acctId);
	}

}

1.4 Compose a cancel service

@Service("accountServiceCancel")
public class AccountServiceCancel implements IAccountService {

	@Resource(name = "jdbcTemplate")
	private JdbcTemplate jdbcTemplate;

	@Transactional
	public void increaseAmount(String accountId, double amount) throws ServiceException {
	    this.jdbcTemplate.update("update tb_account set frozen = frozen - ? where acct_id = ?", amount, acctId);
	}

}

2. Documentation & Samples

3. Features

  • support declarative transaction management
  • support normal transaction, TCC transaction, compensating service transaction
  • support distributed transaction scenarios. e.g. multi-datasource, cross-applications and cross-servers transaction
  • support long live transaction
  • support Dubbo framework
  • support Spring Cloud
  • provide solutions for service idempotence in framework layer

4. Contact Me

If you have any questions or comments regarding this project, please feel free to contact me at:

  1. send mail to bytefox#126.com OR
  2. add Tecent QQ group 537445956/606453172/383515467

We will review all the suggestions and implement good ones in future release.