Introduction to seata

Introduction to Seata

Seata is an open-source distributed transaction framework initially started by Alibaba's middleware team under the name Fescar, which was later renamed to Seata. It aims to provide high-performance and easy-to-use distributed transaction services in a microservices architecture.

Reasons for Choosing Seata

  1. Backed by Alibaba: With the support of Alibaba's dedicated team for promotion and technical development, Seata ensures robust and reliable solutions.
  2. Proven Track Record: It has been widely used in production environments without significant issues, notably supporting Alibaba's ecosystems during high-traffic events
  3. Integration with Mainstream Microservices Frameworks: Seata seamlessly integrates with popular microservices frameworks, making it a versatile choice for various architectures.
  4. Active Community and Comprehensive Documentation: The high activity in its community and the availability of detailed documentation make it a user-friendly option.
  5. Commercial Product Support with GTS: Alibaba Cloud's commercial product, GTS, offers seamless migration and support for Seata, enhancing its usability in enterprise environments.
  6. Support different mode like AT,TCC and sage

Seata's Core Components

Unique Feature: XID

Seata introduces the concept of an XID (Global Transaction ID), generated by the TC when a global transaction is initiated by the TM. This XID is propagated across microservices in the call chain, linking multiple sub-transactions together.

Transaction Process in Seata

  1. Transaction Initiation: A TM in Service A requests the TC to begin a global transaction, which generates a unique XID.
  2. Branch Registration: Service A's RM registers a branch transaction with the TC.
  3. Database Operations: Service A performs database operations as part of its branch transaction.
  4. Service Invocation: Service A invokes Service B, propagating the XID in the microservice call chain context.
  5. Branch Inclusion: Service B's RM registers a branch transaction with the TC, incorporating it into the global transaction associated with the XID.
  6. Completion and Resolution: After the transaction chain completes, the TM decides to commit or rollback the global transaction based on the outcome, instructing the TC accordingly.
  7. TC Coordination: The TC then orchestrates all the branch transactions under the XID to commit or rollback.

Introduction to seata 2023-11-20 22.04.08.excalidraw.png

Key Role of UNDO_LOG

Seata utilizes the UNDO_LOG table, a rollback log record table, as a critical component for implementing distributed transactions. This table, created in each application's database requiring distributed transactions, stores before-and-after data images as rollback logs, enabling transactions to be rolled back in case of anomalies.

CREATE TABLE `undo_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'increment id',
  `branch_id` bigint(20) NOT NULL COMMENT 'branch transaction id',
  `xid` varchar(100) NOT NULL COMMENT 'global transaction id',
  `context` varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',
  `rollback_info` longblob NOT NULL COMMENT 'rollback info',
  `log_status` int(11) NOT NULL COMMENT '0:normal status,1:defense status',
  `log_created` datetime NOT NULL COMMENT 'create datetime',
  `log_modified` datetime NOT NULL COMMENT 'modify datetime',
  `ext` varchar(100) DEFAULT NULL COMMENT 'reserved field',
  PRIMARY KEY (`id`),
  UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='AT transaction mode undo table';

Conclusion

Seata stands out as a robust, reliable, and versatile solution for managing distributed transactions in microservices architectures. Its design, backed by Alibaba's expertise, provides a comprehensive solution for developers facing the challenges of maintaining data consistency across distributed services. With its active community, comprehensive documentation, and compatibility with various transaction modes, Seata is well-positioned to be a go-to framework for organizations aiming to implement efficient and reliable distributed transaction systems.