Fescar is an easy-to-use, high-performance, java based, open source distributed transaction solution.
What is Fescar?
A distributed transaction solution with high performance and ease of use for microservices architecture.
Distributed Transaction Problem in Microservices
Let's imagine a traditional monolithic application. Its business is built up with 3 modules. They use a single local data source.
Naturally, data consistency will be guaranteed by the local transaction.
Things have changed in microservices architecture. The 3 modules mentioned above are designed to be 3 services on top of 3 different data sources (Pattern: Database per service). Data consistency within every single service is naturally guaranteed by the local transaction.
But how about the whole business logic scope?
How Fescar do?
Fescar is just a solution to the problem mentioned above.
Firstly, how to define a Distributed Transaction?
We say, a Distributed Transaction is a Global Transaction which is made up with a batch of Branch Transaction, and normally Branch Transaction is just Local Transaction.
There are 3 basic components in Fescar:
- Transaction Coordinator(TC): Maintain status of global and branch transactions, drive the global commit or rollback.
- Transaction Manager(TM): Define the scope of global transaction: begin a global transaction, commit or rollback a global transaction.
- Resource Manager(RM): Manage resources that branch transactions working on, talk to TC for registering branch transactions and reporting status of branch transactions, and drive the branch transaction commit or rollback.
A typical lifecycle of Fescar managed distributed transaction:
- TM asks TC to begin a new global transaction. TC generates an XID representing the global transaction.
- XID is propagated through microservices' invoke chain.
- RM register local transaction as a branch of the corresponding global transaction of XID to TC.
- TM asks TC for committing or rollbacking the corresponding global transaction of XID.
- TC drives all branch transactions under the corresponding global transaction of XID to finish branch committing or rollbacking.
For more details about principle and design, please go to Fescar wiki page.
History
- TXC: Taobao Transaction Constructor. Alibaba middleware team start this project since 2014 to meet distributed transaction problem caused by application architecture change from monolithic to microservices.
- GTS: Global Transaction Service. TXC as an Aliyun middleware product with new name GTS was published since 2016.
- Fescar: we start the open source project Fescar based on TXC/GTS since 2019 to work closely with the community in the future.
Maven dependency
<fescar.version>0.4.0</fescar.version> <dependency>
<groupId>com.alibaba.fescar</groupId>
<artifactId>fescar-all</artifactId>
<version>${fescar.version}</version>
</dependency>