Architecture Expert
Distributed Transactions — Overview¶
Distributed TransactionsOutbox2PC 3 min read
How to handle transactions across microservices. 2PC, Saga, Outbox pattern, and TCC.
2PC¶
Two-Phase Commit: blocking, slow, coordinator = SPOF. Not used in microservices.
Outbox Pattern¶
BEGIN;
INSERT INTO orders (id, total) VALUES ('ord-1', 1000);
INSERT INTO outbox (aggregate_type, payload) VALUES (
'Order', '{"type": "OrderCreated", "orderId": "ord-1"}'
);
COMMIT;
-- Debezium CDC reads the outbox and publishes events
Saga vs TCC¶
- Saga — sequence of local transactions + compensation
- TCC (Try-Confirm-Cancel) — reservation, then confirmation/cancellation
Summary¶
Saga is the most common choice, Outbox solves reliable messaging. Avoid 2PC in microservices.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.