Two-phase commit (2PC)
A protocol where a coordinator asks every database to prepare a change, then tells all of them to commit or all of them to roll back.
It gives one atomic transaction across several resources. The cost is that participants hold locks while waiting for the coordinator, a coordinator failure can leave them blocked, and throughput drops as participants are added. Most message brokers, SaaS APIs and many cloud databases do not take part in it at all, which is why services usually use sagas and an outbox instead.
Related terms
- Saga pattern: A business process across several services run as a chain of local transactions, with a compensating action to undo each step if a later one fails.
- Eventual consistency: A guarantee that copies of data will agree once updates stop arriving, but may briefly show different values in the meantime.
- Transactional outbox: Saving an event to an outbox table in the same database transaction as the change itself, then publishing it to the broker separately.
