October 31, 2024 4 min read A to Z Series: X Home

XID: One Transaction Id Across Systems

An XID is a globally unique transaction id that names one distributed transaction across every participant.

I use an XID when a business transaction crosses services and needs one identity everywhere. It is not just an idempotency key; it is the shared transaction id operators, logs, traces, and participants can all follow.

One transaction needs one name everywhere

When I talk about "One transaction needs one name everywhere", I am really asking what XID does when a message is late, duplicated, or missing.

Without a shared transaction id, each service may store its own local id. During an incident, operators then have to stitch together order id, payment id, ledger id, and message id. XID gives the distributed transaction one system wide identity.

Checkout transaction example

I use "Checkout transaction example" to keep XID grounded in a real system, because abstract patterns are too easy to agree with and too hard to operate.

A checkout creates XID TX 891. Order, payment, inventory, and ledger all store TX 891 so support can trace the complete transaction from one value.

XID propagation code

When I show "XID propagation code", I want the code in XID to reveal the production decision, not just the syntax.

Create the transaction id once and carry it through every participant:

String xid = xidGenerator.next();
orderService.create(xid, order);
paymentService.authorize(xid, payment);
ledgerService.post(xid, ledgerEntry);

The same XID travels through order, payment, and ledger calls. That gives the whole transaction one system-wide identity for audit and recovery.

Sequence diagram: carry the transaction id

carry the transaction id The same XID appears in every participant so the transaction has one system wide identity. sd carry the transaction id Checkout API Checkout API TransactionCoordinator TransactionCoordinator Order Service Order Service Payment Service Payment Service Ledger Service Ledger Service Create global XID TX891. Send work with XID TX891. Send work with the same XID. Store ledger entries with XID TX 891.

The same XID appears in every participant so the transaction has one system wide identity.

The system wide identity rule

Next transaction topics

Written by Arunkumar Ganesan.

What I learnt is that a good XID makes debugging feel less like archaeology because every participant carries the same business thread.

#DistributedSystems #Transactions #Tracing #Reliability