DataBurst Data Engineering Wiki - Roadmap Step-by-Step: https://wiki.databurst.tech/docs/roadmap/ - Introduction: https://wiki.databurst.tech/docs/roadmap/introduction/ - Programming Language: https://wiki.databurst.tech/docs/roadmap/programming-language/ - Python: https://wiki.databurst.tech/docs/roadmap/programming-language/python/ - Java: https://wiki.databurst.tech/docs/roadmap/programming-language/java/ - Scala: https://wiki.databurst.tech/docs/roadmap/programming-language/scala/ - Go: https://wiki.databurst.tech/docs/roadmap/programming-language/go/ - Rust: https://wiki.databurst.tech/docs/roadmap/programming-language/rust/ - Operating System: https://wiki.databurst.tech/docs/roadmap/operating-system/ - Windows: https://wiki.databurst.tech/docs/roadmap/operating-system/windows/ - Linux: https://wiki.databurst.tech/docs/roadmap/operating-system/linux/ - Networking: https://wiki.databurst.tech/docs/roadmap/networking/ - Protocols: https://wiki.databurst.tech/docs/roadmap/networking/protocols/ - TCP/IP: https://wiki.databurst.tech/docs/roadmap/networking/protocols/tcp/ - DNS: https://wiki.databurst.tech/docs/roadmap/networking/protocols/dns/ - HTTP: https://wiki.databurst.tech/docs/roadmap/networking/protocols/http/ - HTTPS: https://wiki.databurst.tech/docs/roadmap/networking/protocols/https/ - SSH: https://wiki.databurst.tech/docs/roadmap/networking/protocols/ssh/ - UDP: https://wiki.databurst.tech/docs/roadmap/networking/protocols/udp/ - Concepts: https://wiki.databurst.tech/docs/roadmap/networking/concepts/ - IP addressing: https://wiki.databurst.tech/docs/roadmap/networking/concepts/ip-addressing/ - DHCP: https://wiki.databurst.tech/docs/roadmap/networking/concepts/dhcp/ - Firewalls: https://wiki.databurst.tech/docs/roadmap/networking/concepts/firewalls/ - VPN: https://wiki.databurst.tech/docs/roadmap/networking/concepts/vpn/ - General Software Engineering Skills: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/ - OAuth: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/oauth/ - JWT: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/jwt/ - GraphQL: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/graphql/ - REST: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/rest/ - gRPC: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/grpc/ - Caching: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/caching/ - Web Frameworks and API Development: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/ - Python: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/python/ - Go: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/go/ - Java: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/java/ - Version Control System: https://wiki.databurst.tech/docs/roadmap/version-control-system/ - git: https://wiki.databurst.tech/docs/roadmap/version-control-system/git/ - Version Control System Hosting: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/ - Github: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/github/ - Gitlab: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/gitlab/ - BitBucket: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/bitbucket/ - Distributed Systems Concepts: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/ - CAP: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/cap/ - PACELC: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/pacelc/ - Sharding: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/sharding/ - Clock: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/clock/ - ACID: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/acid/ - Replication: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/replication/ - Distributed Transactions: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/transaction/ - Indexing: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/indexing/ - Batch and Stream Processing: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/batch-and-stream-processing/ - Consistency vs Eventual Consistency: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/consistency-vs-eventual-consistency/ - Normalization or Denormalization: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/normalization-or-denormalization/ - SQL Fundamentals: https://wiki.databurst.tech/docs/roadmap/sql-fundamentals/ - Basic SQL: https://wiki.databurst.tech/docs/roadmap/sql-fundamentals/basic-sql/ - Advanced SQL: https://wiki.databurst.tech/docs/roadmap/sql-fundamentals/advanced-sql/ - Databases: https://wiki.databurst.tech/docs/roadmap/databases/ - Relational: https://wiki.databurst.tech/docs/roadmap/databases/relational/ - NoSQL: https://wiki.databurst.tech/docs/roadmap/databases/nosql/ - Columnar: https://wiki.databurst.tech/docs/roadmap/databases/nosql/columnar/ - Document Based: https://wiki.databurst.tech/docs/roadmap/databases/nosql/document-based/ - Key-Value: https://wiki.databurst.tech/docs/roadmap/databases/nosql/key-value/ - Time Series: https://wiki.databurst.tech/docs/roadmap/databases/nosql/time-series/ - Vector: https://wiki.databurst.tech/docs/roadmap/databases/nosql/vector/ - Graph: https://wiki.databurst.tech/docs/roadmap/databases/nosql/graph/ - NewSQL: https://wiki.databurst.tech/docs/roadmap/databases/nosql/newsql/ - Data Modeling: https://wiki.databurst.tech/docs/roadmap/data-modeling/ - Star Schema (Ralph Kimball): https://wiki.databurst.tech/docs/roadmap/data-modeling/star-schema/ - Snowflake: https://wiki.databurst.tech/docs/roadmap/data-modeling/snowflake/ - Data Vault: https://wiki.databurst.tech/docs/roadmap/data-modeling/data-vault/ - Data Management Architecture: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/ - Relational Data Warehouse: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/relational-data-warehouse/ - Data Lake: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-lake/ - Modern Data Warehouse: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/modern-data-warehouse/ - Data Fabric: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-fabric/ - Data Mart: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-mart/ - Data Lakehouse: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-lakehouse/ - Data Mesh: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-mesh/ - Data Integration: https://wiki.databurst.tech/docs/roadmap/data-integration/ - ETL: https://wiki.databurst.tech/docs/roadmap/data-integration/etl/ - ELT: https://wiki.databurst.tech/docs/roadmap/data-integration/elt/ - CDC: https://wiki.databurst.tech/docs/roadmap/data-integration/cdc/ - Reverse ETL: https://wiki.databurst.tech/docs/roadmap/data-integration/reverse-etl/ - Storage: https://wiki.databurst.tech/docs/roadmap/storage/ - Block Storage: https://wiki.databurst.tech/docs/roadmap/storage/block-storage/ - Object Storage: https://wiki.databurst.tech/docs/roadmap/storage/object-storage/ - File Formats and Serialization: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/ - File Formats: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/ - CSV: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/csv/ - JSON: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/json/ - Parquet: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/parquet/ - XML: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/xml/ - Serialization: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/serialization/ - Avro: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/serialization/avro/ - Protocol Buffers: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/serialization/protobuf/ - Query Engine: https://wiki.databurst.tech/docs/roadmap/query-engine/ - Apache Hive: https://wiki.databurst.tech/docs/roadmap/query-engine/hive/ - SparkSQL: https://wiki.databurst.tech/docs/roadmap/query-engine/sparksql/ - Trino: https://wiki.databurst.tech/docs/roadmap/query-engine/trino/ - Presto: https://wiki.databurst.tech/docs/roadmap/query-engine/presto/ - Data Architecture: https://wiki.databurst.tech/docs/roadmap/data-architecture/ - Kappa: https://wiki.databurst.tech/docs/roadmap/data-architecture/kappa/ - Lambda: https://wiki.databurst.tech/docs/roadmap/data-architecture/lambda/ - Data Processing: https://wiki.databurst.tech/docs/roadmap/data-processing/ - Pipeline Orchestration: https://wiki.databurst.tech/docs/roadmap/pipeline-orchestration/ - Messaging and Streaming Platform: https://wiki.databurst.tech/docs/roadmap/messaging-and-streaming-platform/ - Data Governance: https://wiki.databurst.tech/docs/roadmap/data-governance/ - Data Quality: https://wiki.databurst.tech/docs/roadmap/data-governance/data-quality/ - Data Visualization: https://wiki.databurst.tech/docs/roadmap/data-visualization/ - Containerization: https://wiki.databurst.tech/docs/roadmap/containerization/ - Docker: https://wiki.databurst.tech/docs/roadmap/containerization/docker/ - Podman: https://wiki.databurst.tech/docs/roadmap/containerization/podman/ - containerd: https://wiki.databurst.tech/docs/roadmap/containerization/containerd/ - Container Orchestration: https://wiki.databurst.tech/docs/roadmap/container-orchestration/ - Kubernetes: https://wiki.databurst.tech/docs/roadmap/container-orchestration/kubernetes/ - Docker Swarm: https://wiki.databurst.tech/docs/roadmap/container-orchestration/docker-swarm/ - Apache Mesos: https://wiki.databurst.tech/docs/roadmap/container-orchestration/apache-mesos/ - CI/CD: https://wiki.databurst.tech/docs/roadmap/cicd/ - DataOps: https://wiki.databurst.tech/docs/roadmap/cicd/dataops/ - Infrastructure as Code: https://wiki.databurst.tech/docs/roadmap/infrastructure-as-code/ - Configuration Management: https://wiki.databurst.tech/docs/roadmap/infrastructure-as-code/configuration-management/ - Infrastructure Provisioning: https://wiki.databurst.tech/docs/roadmap/infrastructure-as-code/infrastructure-provisioning/ - Observability: https://wiki.databurst.tech/docs/roadmap/observability/ - Logging: https://wiki.databurst.tech/docs/roadmap/observability/logging/ - Monitoring: https://wiki.databurst.tech/docs/roadmap/observability/monitoring/ - Tracing: https://wiki.databurst.tech/docs/roadmap/observability/tracing/ - Glossary: https://wiki.databurst.tech/docs/roadmap/glossary/
$ man 2pc # all nodes commit, or none do
# Distributed Transactions A **distributed transaction** is a group of changes that spans more than one database, shard or service and must **all succeed or all fail**. Moving 100 from Alice's account on one shard to Sam's account on another is the classic example: debiting Alice without crediting Sam is not acceptable, even if a machine crashes halfway. Inside one database this is plain [ACID]({{< relref "/docs/roadmap/distributed-systems-concepts/acid" >}}): the write-ahead log makes the commit atomic. Across machines there is no shared log, so the machines need a protocol to agree on one outcome. ## Two-phase commit (2PC) 2PC adds a **coordinator** that asks every participant to get ready, then tells all of them the single decision. {{< fig kicker="$ ./transfer --from alice@nodeA --to sam@nodeB --amount 100" title="Two-phase commit, and what happens when the coordinator dies" >}} COORDINATOR txn 81: Alice → Sam 100 log: (empty) NODE A Alice = 500 idle NODE B Sam = 200 idle PREPARE ↓ ↓ PREPARE YES ↑ ↑ YES Alice = 400 ? PREPARED · row locked Sam = 300 ? PREPARED · row locked log: COMMIT txn 81 CRASHED IN DOUBT · lock held IN DOUBT · lock held other writes to Alice and Sam wait… COORDINATOR restarted, reads log log: COMMIT txn 81 COMMIT ↓ ↓ COMMIT Alice = 400 COMMITTED · unlocked Sam = 300 COMMITTED · unlocked
NO.STEPFROMTOTYPEINFO
101coordinatorA, BPREPAREcan you commit txn 81?
202A, BcoordinatorVOTE YESchanges on disk, rows locked, promise to obey
303coordinatorits logDECIDECOMMIT written to disk
403coordinator-CRASHdecision never sent · A and B blocked
504coordinatorA, BCOMMITrecovered from log · locks released
  1. Transfer 100 from Alice (Node A) to Sam (Node B). A coordinator drives the commit.
  2. Phase 1: the coordinator sends PREPARE to every participant.
  3. Each participant writes its changes durably, locks the rows and votes YES. A YES is a promise: "I will commit if told to, even after a crash."
  4. The coordinator logs COMMIT, then crashes before telling anyone. The participants are in doubt: they promised, so they cannot abort alone, and they do not know the decision. Locks stay held and other writes block.
  5. Phase 2: the coordinator restarts, reads COMMIT from its log and resends it. Both nodes commit and release their locks. Atomic, but only after waiting.
{{< /fig >}} That waiting is the key weakness of 2PC: it is **atomic but blocking**. A dead coordinator can freeze rows on healthy machines for as long as it stays down. 2PC also needs every participant to vote, so one slow node slows every transaction. **Three-phase commit (3PC)** tries to remove the blocking with an extra round, but it assumes network delays are bounded, which real networks do not guarantee. It is taught often and used rarely. ## How modern systems commit across machines | Approach | Idea | Atomic? | Where you meet it | |---|---|---|---| | **2PC / XA** | Coordinator + prepare/commit rounds | Yes, blocking | XA in Java/.NET, PostgreSQL `PREPARE TRANSACTION`, MySQL XA | | **2PC over consensus groups** | Each participant and the coordinator state are replicated with Raft or Paxos, so a single crash does not block | Yes | Google Spanner, CockroachDB, YugabyteDB, TiDB | | **Saga** | A chain of local transactions, each with a compensating action ("refund" undoes "charge") | No, eventually consistent | Microservice workflows, Temporal, AWS Step Functions | | **Transactional outbox** | Write the business row and an "event to publish" row in one local transaction; a relay or CDC publishes it | Yes for DB + event | Debezium outbox, event-driven services | | **Kafka transactions** | Producer writes to several partitions and commits offsets atomically via a transaction coordinator | Yes, within Kafka | Exactly-once Kafka Streams and Flink sinks | Spanner also uses **TrueTime** (GPS and atomic clocks with a bounded error) to give every transaction a globally meaningful timestamp. See [Clock]({{< relref "/docs/roadmap/distributed-systems-concepts/clock" >}}). ## When to use what - **Same database, many shards**: let a database built for it (Spanner, CockroachDB, YugabyteDB, Citus) handle commit. Do not build your own. - **Database + message broker**: use the outbox pattern, not a "write to DB, then publish to Kafka" dual write. - **Several services owned by different teams**: use a saga with idempotent steps and compensations. 2PC across services couples their availability. - **Data pipelines**: make sinks idempotent (upsert by key, or overwrite a partition) so a retried job never double-writes. ## Common mistakes - **Dual writes.** Writing to the database and then to Kafka (or a cache) without a transaction. A crash in between leaves them disagreeing forever. - **Forgotten prepared transactions.** An orphaned `PREPARE TRANSACTION` in PostgreSQL holds locks and blocks vacuum until someone commits or rolls it back. - **Sagas without compensation for every step.** If step 4 fails, steps 1 to 3 must be undone, and the undo must itself be retryable. - **Assuming exactly-once delivery.** Networks deliver at-least-once; exactly-once *effects* come from idempotency plus transactions. ## Learning Resources ### Books - *Designing Data-Intensive Applications* (2nd ed.), Martin Kleppmann and Chris Riccomini: chapters on transactions and consistency/consensus - [Database Internals](https://www.oreilly.com/library/view/database-internals/9781492040330/), Alex Petrov: chapter 13, distributed transactions ### Papers - [Consensus on Transaction Commit](https://www.microsoft.com/en-us/research/publication/consensus-on-transaction-commit/): Jim Gray and Leslie Lamport, why 2PC blocks and how Paxos Commit fixes it - [Spanner: Google's Globally-Distributed Database](https://research.google/pubs/spanner-googles-globally-distributed-database-2/) - [Sagas](https://www.cs.cornell.edu/andru/cs711/2002fa/reading/sagas.pdf): Garcia-Molina and Salem, 1987 ### Articles and videos - [Pattern: Saga](https://microservices.io/patterns/data/saga.html) and [Pattern: Transactional outbox](https://microservices.io/patterns/data/transactional-outbox.html), Chris Richardson - [Distributed Systems 7.1: Two-phase commit](https://www.youtube.com/watch?v=-_rdWB9hN1c), Martin Kleppmann - [Handle Distributed Transactions: 2PC, 3PC, Saga](https://www.youtube.com/watch?v=ET_DnJgfplY)