# Distributed transactions: What, why, and how to build a distributed transactional application

DevFeed: [Distributed transactions: What, why, and how to build a distributed transactional application](<https://devfeed.tech/articles/distributed-transactions-what-why-and-how-to-build-a-distributed-transactional-application-23780.md>)

Original publisher: [Read original article](<https://cockroachlabs.com/blog/distributed-transactions-what-why-and-how-to-build-a-distributed-transactional-application>)

Author: Charlie Custer

Published: 2023-02-16T00:00:00Z

Content type: article

Language: en

Sources: [Cockroach Labs](<https://devfeed.tech/sources/cockroach-labs.md>)

Topics: [Transactions](<https://devfeed.tech/topics/transactions.md>), [Distributed Systems & Parallel Computing](<https://devfeed.tech/topics/distributed-systems-parallel-computing.md>), [Database](<https://devfeed.tech/topics/database.md>), [CockroachDB](<https://devfeed.tech/topics/cockroachdb.md>), [database-consistency](<https://devfeed.tech/topics/database-consistency.md>), [Raft](<https://devfeed.tech/topics/raft.md>), [acid](<https://devfeed.tech/topics/acid.md>)

Tags: [availability](<https://devfeed.tech/tags/availability.md>), [consistency](<https://devfeed.tech/tags/consistency.md>), [database](<https://devfeed.tech/tags/database.md>), [distributed-transactions](<https://devfeed.tech/tags/distributed-transactions.md>), [fault-tolerance](<https://devfeed.tech/tags/fault-tolerance.md>), [high-availability](<https://devfeed.tech/tags/high-availability.md>), [scalability](<https://devfeed.tech/tags/scalability.md>), [transactions](<https://devfeed.tech/tags/transactions.md>)

## AI overview

Distributed transactions coordinate data changes across database nodes, preserving the all-or-nothing behavior expected of a transaction. The article compares three patterns: two-phase commit keeps nodes consistent by requiring each to prepare and then commit, but locks resources, can bottleneck, and fails if any node is unavailable. Active-passive replicas allow a passive node to take over after an active-node failure, though failover can cause a brief outage and writes remain limited to one node. In a multi-active system such as CockroachDB, all nodes can handle reads and writes; Raft lets a transaction commit when a majority agree, and the database manages routing and consistency. This can support scaling and availability while preserving consistency, but building such a system from scratch is highly complex, so adopting it generally means choosing or migrating to a purpose-built database.

## Source excerpt

Transactions make up an important part of the database workload for most modern applications. And when it comes time to scale up operations for a growing business, distributing those workloads across multiple hardware systems for horizontal scalability, high availability, and fault tolerance is often an important part of the plan.