Quick revision
The short answer
I would replace the XA transactions with a transactional outbox, writing each business change and its outgoing message in one local Oracle transaction and publishing to MQ afterwards, together with idempotent consumers so redelivered messages are harmless. For business processes that span several services I would use sagas with compensating actions, and accept eventual consistency by designing user-facing states such as pending and confirmed that make the in-between moments honest.
What to remember
In this answer, we saw that XA gave atomic commits across Oracle and IBM MQ, and that after splitting into services the naive commit-then-send loses or duplicates messages. The transactional outbox writes the change and the message in one local transaction and publishes later, idempotent consumers make at-least-once delivery safe, sagas with compensating actions handle multi-step processes, and explicit states such as PENDING and CONFIRMED let users and support live with eventual consistency.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would replace the XA transactions with a transactional outbox, writing each business change and its outgoing message in one local Oracle transaction and publishing to MQ afterwards, together with idempotent consumers so redelivered messages are harmless. For business processes that span several services I would use sagas with compensating actions, and accept eventual consistency by designing user-facing states such as pending and confirmed that make the in-between moments honest.
Why this question is asked
Many large systems built in the 2000s rely on XA: a single transaction updates Oracle and puts a message on IBM MQ, and the application server's transaction manager makes both happen or neither. When we split such a system into services, each with its own database, that safety net disappears, and the naive replacement of committing to the database and then sending the message silently loses or duplicates messages. Interviewers ask this design question to see whether we know the patterns that give reliability without distributed transactions, and whether we think about what users see. In this answer, we will see what XA was guaranteeing, why it does not carry over, then build the replacement from the outbox, idempotent consumers and sagas, and finish with designing for eventual consistency.
1What the XA Transaction Was Guaranteeing
With XA, the application server coordinated Oracle and MQ through two-phase commit: both prepared, both committed. The guarantee was simple: if the order row exists, the OrderPlaced message was sent, and if the transaction rolled back, neither happened. Consumers reading from MQ could also take part in XA, so consuming a message and updating their database was atomic too.
In a service architecture this stops working well. Each service owns its database, services run in containers without a durable transaction log, managed brokers often do not support XA, and coupling several services into one two-phase commit makes them fail together. So we need the same business outcome with only local transactions.
2Why Commit-Then-Send Is Not Enough
The first idea is to commit the database transaction and then send the message. But the process can crash after the commit and before the send, and the message is lost. Sending first and committing after is worse: the commit can fail after the message is out, and consumers act on an order that does not exist. Retrying the send helps with brief failures but not with a crash. This is the dual write problem: two systems, two commits, no atomicity between them.
3The Transactional Outbox
The outbox pattern turns the dual write into a single write. In the same local Oracle transaction that saves the order, we insert a row into an outbox table describing the message. Both rows commit together, because they are in the same database. A separate relay process then reads unpublished outbox rows, sends them to MQ, and marks them as sent. If the relay crashes after sending but before marking, it sends the row again on restart, so delivery is at least once, never lost.
8 messages in order. Play them, or step through them one at a time.
At-least-once delivery from the relay, made safe by the consumer's processed-id check.
The relay can be a polling job, as above, or change data capture such as Debezium reading the database log, which avoids polling and keeps order. The event id travels with the message so consumers can recognise duplicates.
4Idempotent Consumers
Because the relay and MQ deliver at least once, consumers must handle the same message twice without doing the work twice. An idempotent consumer records the ids of messages it has processed, in its own database and in the same local transaction as its business change. When a message arrives, it checks the id first; if it has seen it, it acknowledges and does nothing.
With a unique constraint on the processed-id table, two copies arriving at the same moment cannot both succeed: one insert fails and its transaction rolls back. Some operations are naturally idempotent, such as setting a status to SHIPPED, but charging a card or adding to a balance are not, so the id check is the safe default.
5Sagas for Multi-Step Processes
Some legacy XA transactions covered a whole business process, for example reserve stock, charge the customer and create a shipment. After the split these are three services, and there is no single transaction. A saga models the process as a sequence of local transactions, one per service, each publishing an event that triggers the next. If a later step fails, the saga runs compensating actions that undo the earlier steps in business terms: release the stock, refund the charge.
Sagas can be choreographed, where each service reacts to the previous event, or orchestrated, where a coordinator service tells each participant what to do and tracks the state. For a process with more than three or four steps, orchestration is usually easier to understand and monitor. Compensations are not true rollbacks: a refund is a new transaction the customer can see, so they must be designed with the business.
- Reserve stockInventory service, local tx
- Charge paymentPayment service, local tx
- Payment succeeded?Card declined or timeoutYesCreate shipmentNoCompensate: release stock
- Create shipmentShipping service, local tx
- Order CONFIRMEDShown to the customer
- Compensate: release stockOrder REJECTED, customer told
6 steps in order. Play them, or step through them one at a time.
6Designing for Eventual Consistency
Without XA, there are moments when the order exists but billing has not happened yet. We should make those moments visible rather than hiding them. The order gets explicit states such as PENDING, CONFIRMED and REJECTED, the user interface says the order is being processed, and notifications tell the customer when it is confirmed. Reports and support tools need to understand these states too.
Monitoring completes the design: alert when outbox rows stay unsent for more than a minute, when sagas stay in a middle state too long, or when messages land on the dead-letter queue. I would migrate one flow at a time, running the new path alongside the old XA path in staging and comparing results before switching production.
7Follow-up questions
Can we keep XA only between Oracle and MQ inside one service?
Yes, if that service stays on a platform with a reliable JTA manager and both resources support XA. It can be a reasonable transition step. But it keeps the operational costs of XA, and once messages cross into other services the outbox is needed anyway, so it is usually better to move to the outbox early.
What about message ordering?
The outbox preserves the commit order within one relay if it reads rows in sequence. For strict ordering per entity, such as all events for one order, we publish them with a key or to a partition that the consumer processes in order, and the consumer can check a version number to skip stale events.
How do you clean up the outbox and processed-id tables?
Delete or archive sent outbox rows after a retention period, for example seven days, with a scheduled job. Processed-id records only need to live longer than the maximum redelivery window, so a similar retention works. Both tables should be indexed on the columns used for lookup.
8Conclusion
In this answer, we saw that XA gave atomic commits across Oracle and IBM MQ, and that after splitting into services the naive commit-then-send loses or duplicates messages. The transactional outbox writes the change and the message in one local transaction and publishes later, idempotent consumers make at-least-once delivery safe, sagas with compensating actions handle multi-step processes, and explicit states such as PENDING and CONFIRMED let users and support live with eventual consistency.
Open with
First I would be clear about what XA was giving us: the Oracle change and the MQ message committed together or not at all. After the split we cannot keep that across services, and the naive approach of committing and then sending loses messages if the process crashes in between.
Then, if they want more
So I would use the transactional outbox. In the same local Oracle transaction as the business change, I insert an outbox row with the event, so both commit atomically. A relay, either polling or change data capture like Debezium, publishes those rows to MQ and marks them sent. If it crashes it resends, so delivery is at least once.
That means every consumer must be idempotent: it records the message id in its own database in the same transaction as its work, with a unique constraint, and ignores duplicates.
For processes that span several services, like reserve stock, charge, ship, I would use a saga, usually orchestrated, where each step is a local transaction and failures trigger compensations like releasing stock or refunding.
Finally I would design for eventual consistency in the product: explicit states like PENDING and CONFIRMED, clear messages to users, and alerts on stuck outbox rows and sagas. I would migrate flow by flow, comparing results with the old XA path.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Jakarta EE specifications
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A legacy system uses XA transactions between Oracle and IBM MQ. You are splitting it...": https://scrivio-interview-library.netlify.app/java/jakarta-ee-platform/881b38fd63/