Quick revision
The short answer
I would draw service boundaries around consistency needs: data that must change atomically stays in one service and one database. Across services, consistency comes from sagas with compensating actions, outbox-based events and idempotent consumers, plus explicit agreements on which inconsistencies are acceptable and for how long, enforced by reconciliation jobs. I would avoid distributed transactions between services, and treat growing compensation logic as a sign that a boundary is in the wrong place.
What to remember
In this answer, we saw that splitting a monolith removes the transactions that kept cross-cutting data consistent. The long-term strategy is to keep atomic invariants inside one service, use sagas with compensation, outbox events and idempotent consumers across services, agree in writing how long each inconsistency may last and back that with reconciliation, avoid distributed transactions, and treat heavy compensation as a sign of a wrong boundary.
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 draw service boundaries around consistency needs: data that must change atomically stays in one service and one database. Across services, consistency comes from sagas with compensating actions, outbox-based events and idempotent consumers, plus explicit agreements on which inconsistencies are acceptable and for how long, enforced by reconciliation jobs. I would avoid distributed transactions between services, and treat growing compensation logic as a sign that a boundary is in the wrong place.
Why this question is asked
A monolith on one database gets consistency almost for free: wrap the work in a transaction and the database guarantees all or nothing. Splitting it into services takes that guarantee away for every operation that now crosses a boundary, and many migrations fail because they discover this one operation at a time. Interviewers ask this at the principal level to see whether we can set a strategy before the split, not patch it after. In this answer, we will see what changes, how to decide where data stays together, which tools replace the transaction across services, and how to tell when a boundary is wrong.
1What the Monolith's Transactions Were Doing
In the monolith, placing an order might reserve stock, create the order, charge the customer's credit and write an invoice, all in one transaction. If the credit check failed, the rollback undid the stock reservation and the order. Nobody had to write code to undo anything, and nobody ever saw an order without an invoice.
After the split, Orders, Inventory, Billing and Invoicing each own a database. The same operation now becomes four local transactions in four services. Between them, the system is temporarily inconsistent, and if a later step fails, the earlier ones have already committed. Something must undo them, or the system stays inconsistent.
2Principle 1: Draw Boundaries Around Consistency
The first decision is where to cut. The rule I would set is that data which must change atomically, where even a short inconsistency is unacceptable, stays inside one service and one database. An order and its order lines, or an account and its ledger entries, are examples: an order total that disagrees with its lines for even a second is a bug. Data that can be slightly out of date for a while, like a customer's loyalty points after an order, can live elsewhere.
In practice we list the invariants, the rules that must always hold, and for each one note the data it touches. Invariants that span data inside one candidate service are cheap. Invariants that would span two services are expensive, and each one either moves the boundary or gets an explicit plan.
| Invariant | Tolerance | Strategy |
|---|---|---|
| Order total equals sum of its lines | Never inconsistent | Same service, one transaction |
| Ledger entries balance to zero | Never inconsistent | Same service, one transaction |
| Stock reserved for every confirmed order | Seconds | Saga with compensation |
| Every shipped order has an invoice | Minutes | Outbox event plus reconciliation |
| Loyalty points reflect orders | Hours | Events, daily reconciliation |
3Principle 2: Sagas, Outbox and Idempotent Consumers Across Services
A saga is a sequence of local transactions in different services, where each step has a compensating action that semantically undoes it: release the reserved stock, refund the charge, cancel the order. If step three fails, the saga runs the compensations of steps two and one. It can be orchestrated, with a coordinator that tells each service what to do next, or choreographed, where each service reacts to the previous service's event. Orchestration is easier to follow and monitor for flows with more than three steps.
Each step publishes its result through a transactional outbox, so a committed step always produces its event, and each consumer is idempotent, so a repeated event does no harm. Without these two, a saga loses or duplicates steps under failure, and compensation cannot be trusted.
6 messages in order. Play them, or step through them one at a time.
Each arrow is a local transaction plus an outbox event, never one shared transaction.
4Principle 3: Name the Acceptable Inconsistencies
Eventual consistency is only acceptable if we say what eventual means. For each cross-service invariant, the business agrees how long it may be violated and what happens when it is: stock may lag orders by up to 5 seconds, an invoice may appear up to 10 minutes after shipping. These numbers become monitored targets.
Because messages can still be lost to bugs or misconfiguration, we also build reconciliation jobs: scheduled comparisons between services that find and repair drift, such as shipped orders without invoices. They are the safety net that makes the whole design trustworthy, and their findings are a measure of how well the rest works.
5Principle 4: No Distributed Transactions Between Services
Two-phase commit, 2PC, where a coordinator asks every database to prepare and then to commit, can make cross-service changes atomic. I would not allow it between services as a general tool. Every participant must be available for any of them to commit, so availability drops with each service added; a coordinator failure at the wrong moment leaves locks held until it recovers; and it couples the services' databases so tightly that they are no longer independent. It also does not cover brokers or external APIs. The rare cases where it seems necessary are usually a sign that the data belongs in one service.
6Principle 5: Compensation Complexity Is a Boundary Signal
Finally, the strategy needs a feedback loop. If a saga needs many compensations, if compensations themselves fail often, or if two services constantly call each other to answer a single request, the split is probably in the wrong place. The fix is to merge or move the boundary, which is cheaper early than late. I would review the busiest cross-service flows every few months and track the number of reconciliation corrections per flow as a health measure.
7Follow-up questions
How do you migrate without a big bang?
Extract one service at a time, starting with the one whose data has the fewest cross-boundary invariants. During the transition, the monolith can publish changes through an outbox or CDC so the new service builds its own copy, and the switch of ownership happens when reconciliation shows the copies agree.
Orchestration or choreography?
Choreography is fine for short flows with two or three steps. For longer flows, an orchestrator makes the state of each saga visible in one place, which simplifies monitoring, timeouts and compensation. Tools such as workflow engines can hold that state durably.
What about reads that need data from several services?
Build a read model: a service or table that subscribes to the events and keeps a combined view for queries. It is eventually consistent, which must match the tolerance agreed for that screen.
8Conclusion
In this answer, we saw that splitting a monolith removes the transactions that kept cross-cutting data consistent. The long-term strategy is to keep atomic invariants inside one service, use sagas with compensation, outbox events and idempotent consumers across services, agree in writing how long each inconsistency may last and back that with reconciliation, avoid distributed transactions, and treat heavy compensation as a sign of a wrong boundary.
Open with
My starting point is that the database transaction was doing real work in the monolith, so before we split, we list the invariants and decide where each one lives.
Then, if they want more
Anything that must never be inconsistent, like an order and its lines or a ledger that must balance, stays in one service and one database, and that is how I would draw the boundaries.
For invariants that do cross services, I would use sagas: a sequence of local transactions with a compensating action for each step, orchestrated for longer flows so the state is visible. Each step publishes through a transactional outbox so no event is lost, and consumers deduplicate by event id.
Then I would make eventual consistency concrete: for each cross-service rule, the business agrees how long it may be violated, we monitor it, and we run reconciliation jobs that find and repair drift, because something will always slip through.
I would not use two-phase commit between services; it lowers availability, can leave locks held when the coordinator fails, and couples the databases. And I would treat growing compensation logic or chatty calls between two services as a signal that the boundary is wrong, and be willing to merge them.
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
- Spring Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
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 "Your monolith relied on large database transactions for consistency. As it is split into...": https://scrivio-interview-library.netlify.app/databases/transactions/5f76d97310/