XA Transactions
XA transactions coordinate commits across multiple databases or resource managers (two-phase commit). Use sparingly — they are slow and complex.
XA transactions coordinate commits across multiple databases or resource managers (two-phase commit). Use sparingly — they are slow and complex.
-- Phase 1: Prepare
XA START "txn-001";
UPDATE db1.accounts SET balance = balance - 100 WHERE id = 1;
XA END "txn-001";
XA PREPARE "txn-001";
-- Phase 2: Commit (or Rollback)
XA COMMIT "txn-001";
-- XA ROLLBACK "txn-001";
-- Check pending XA transactions:
XA RECOVER;
Prefer eventual consistency via message queues (Kafka, SQS) over XA in distributed microservices.