As explained previously, there is a big difference between distributed transactions that span multiple heterogeneous storage technologies and those that are internal to a system—that is, where all the participating nodes are part of the same database running the same software. Such internal distributed transactions are a defining feature of “NewSQL” databases such as CockroachDB, TiDB, Spanner, FoundationDB, and YugabyteDB, for example. Some message brokers, such as Kafka, also support internal distributed transactions.
Many of these systems use 2PC to ensure atomicity of transactions that write to multiple shards, yet they don’t suffer from the same problems as XA transactions. Because their distributed transactions don’t need to interface with any other technologies, they avoid the lowest-common-denominator trap—the designers of these systems are free to use better protocols that are more reliable and faster.
The biggest problems with XA can be fixed by the following:
-
Replicating the coordinator, with automatic failover to another coordinator node if the primary one crashes
-
Allowing the coordinator and data shards to communicate directly without intermediary application code
-
Replicating the participating shards so that the risk of having to abort a transaction because of a fault in one of the shards is reduced
-
Coupling the atomic commitment protocol with a distributed concurrency control protocol that supports deadlock detection and consistent reads across shards
Consensus algorithms are commonly used to replicate the coordinator and the database shards. We will see in the related discussion how atomic commitment for distributed transactions can be implemented using a consensus algorithm. These algorithms tolerate faults by automatically failing over from one node to another without any human intervention, while continuing to guarantee strong consistency properties.
The isolation levels offered for distributed transactions depend on the system, but snapshot isolation and serializable snapshot isolation are both possible across shards.