AlgoViz

Two-stage processing

medium 30 min

Two-stage processing, known as two-phase commit (2PC), makes several databases commit or abort together.

Where it shows up

The same pattern appears across everyday software.

  • PostgreSQL

    PREPARE TRANSACTION, COMMIT PREPARED and ROLLBACK PREPARED let an external coordinator run 2PC. The limit max_prepared_transactions is zero by default, which disables the feature, and the manual warns against leaving transactions prepared for long.

  • MariaDB

    Supports XA START, XA PREPARE, XA COMMIT and XA RECOVER. Its documentation notes that external XA needs an external coordinator.

  • Oracle Database

    Distributed transactions use two-phase commit, with a global coordinator and a commit point site. A transaction becomes in doubt if the mechanism fails.

  • Google Spanner

    A write that touches several splits uses standard two-phase commit between the splits, and the participants take locks in the first phase.

  • Apache Kafka

    Its transaction coordinator writes a PREPARE_COMMIT record and then commit markers to the partitions. It is a relative of 2PC inside one system.

  • Apache Seata

    An open-source framework for distributed transactions between services, with several modes besides the saga mode.