Quick revision
The short answer
I would start by finding the data flows where an error costs the most, money, customer trust or regulatory exposure, and require tests against real databases for those, rather than asking for more tests everywhere. Then I would fund shared tooling such as Testcontainers images, data builders and contract tests so teams can meet the bar cheaply, make test quality visible through escaped defects by category, flakiness and build time, give teams dedicated time because test debt always loses to features otherwise, and review the results every quarter.
What to remember
In this answer, we saw how to set direction on test investment for data correctness. We ranked data flows by the cost of their errors and required real-database, concurrency and idempotency tests for the critical ones, funded shared tooling such as Testcontainers images, data builders and contract tests, made quality visible through escaped defects, flakiness and build time, protected dedicated time because test debt otherwise loses to features, and reviewed the results every quarter.
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 start by finding the data flows where an error costs the most, money, customer trust or regulatory exposure, and require tests against real databases for those, rather than asking for more tests everywhere. Then I would fund shared tooling such as Testcontainers images, data builders and contract tests so teams can meet the bar cheaply, make test quality visible through escaped defects by category, flakiness and build time, give teams dedicated time because test debt always loses to features otherwise, and review the results every quarter.
Why this question is asked
When transactional bugs keep reaching production, it is tempting to issue a rule such as 80 percent coverage for everyone. That spreads effort evenly over code that does not deserve it evenly, and coverage says little about whether a transfer can be applied twice. At the senior level, interviewers want to see how we decide where test investment goes, how we make it sustainable across teams, and how we know it is working. In this answer, we will look at how to find where correctness matters most, what kind of tests those flows need, what shared tooling to fund, how to measure and fund the work, and how to review it.
1Find Where Errors Are Most Expensive
Not all data is equal. A wrong recommendation shown on a page is annoying; a payment posted twice, a balance that drifts, or an order that is charged but never shipped costs real money and trust. So the first step is a short exercise with each domain: list the data flows, and for each one estimate what a correctness bug costs and how often such bugs have happened. Incident reports and support tickets from the last year are the best source.
Usually a handful of flows stand out: payments and ledgers, inventory reservations, order state transitions, anything with money or legal meaning. For those, I would set a higher bar. For the long tail, the existing practices may be enough.
| Data flow | Cost of a bug | Required tests |
|---|---|---|
| Payments and ledger postings | money lost, regulatory | real DB, concurrency, idempotency |
| Inventory reservation | oversell, refunds | real DB, concurrent reservations |
| Order state machine | stuck or double-shipped orders | real DB, state transitions, events |
| Profile preferences | minor annoyance | normal unit and slice tests |
2What the Critical Flows Need
For the critical flows, the requirement is tests against a real database engine, the same one used in production, with the real migrations. Most transactional bugs live in exactly the places that mocks and embedded databases cannot reproduce: isolation levels, lock behaviour, constraint checks at flush, generated keys, and what happens when two transactions touch the same rows.
So the bar includes concurrency tests that run two operations at once and check the invariant afterwards, for example that two simultaneous reservations of the last item leave exactly one success. It includes idempotency tests that replay the same message or request and check that money moved once. And it includes tests that run with production-like transaction boundaries rather than inside one big test transaction that rolls back, because that hides flush and lazy loading errors.
3Fund Shared Tooling
If each team must build its own way to start PostgreSQL, load data and simulate a partner, the bar will be met badly or not at all. So I would ask a platform group to provide shared tooling: Testcontainers setups with our database versions and extensions preconfigured and reusable across test classes, data builders that create valid domain objects in one line so tests are short and readable, and contract tests between services so that a change in an event or API shape is caught before it corrupts data downstream.
Notice that this is the cheapest lever we have. One platform engineer for a quarter can save every team weeks, and the tests written on shared tooling look the same, so people can read each other's tests and move between teams easily.
4Make Test Quality Visible
We cannot steer what we cannot see. I would publish a few measures per team and per critical flow. The first is escaped defects by category: how many data correctness bugs reached production, and which kind of test would have caught them. This is the measure that matters most, because it is what the business feels. The second is flakiness: tests that fail without a code change destroy trust in the suite, and teams start ignoring red builds. The third is build time: if the real-database tests make the build twice as slow, people will avoid them, so we watch it and invest in parallelism and container reuse.
Coverage can stay as an internal signal, but it is not the goal. A flow with 60 percent coverage and solid concurrency tests is safer than one with 95 percent coverage of getters.
5Fund the Time Explicitly
Test debt competes with features, and in that competition it loses every sprint unless someone protects it. So I would agree with product leadership on dedicated capacity, for example 15 percent of each critical team's time for two quarters, and tie it to the cost numbers from the first step. It is much easier to fund when we can say that the last three ledger incidents cost a known amount and the plan targets exactly that class of bug.
After the initial investment, the ongoing cost should drop to normal development work, because the tooling exists and new code is written with tests from the start.
6Review Every Quarter and Adjust
Every quarter, I would review the measures with the team leads: escaped defects by category, flakiness, build time, and progress on the critical flows. If escaped bugs drop in one flow, we can relax the investment there; if a new class of bug appears, perhaps from a new event consumer, we add that flow to the critical list. The point is to treat test investment as a portfolio that we rebalance with evidence, not as a rule written once.
- Collect escaped defects, flakiness, build timeper team and critical flow
- Rank flows by cost of errorsincidents, tickets, risk
- Bugs still escaping in a flow?YesRaise its bar and fund toolingNoKeep or relax investment
- Agree capacity with productfor the next quarter
- Review results next quarter
5 steps in order. Play them, or step through them one at a time.
7Follow-up questions
How do you convince product leadership to give up feature time?
With their own numbers. I show what the last year of data correctness incidents cost in refunds, support time and engineering hours, and a plan aimed at that class of bug with a clear time limit and expected reduction. A specific, measured request is far easier to accept than a general call for better quality.
Isn't testing against real databases too slow for every build?
It need not be. Reused containers, parallel test classes and keeping the real-database tests focused on the critical flows usually keep the added time to a few minutes. We also track build time explicitly, so if it grows we invest in speeding it up rather than letting teams skip the tests.
What about bugs that only appear under production load?
Some will. For those, I would add invariant checks in production, for example a nightly job that verifies ledger balances against postings, and alert on differences. Every such finding becomes a new test, so the suite learns from production.
8Conclusion
In this answer, we saw how to set direction on test investment for data correctness. We ranked data flows by the cost of their errors and required real-database, concurrency and idempotency tests for the critical ones, funded shared tooling such as Testcontainers images, data builders and contract tests, made quality visible through escaped defects, flakiness and build time, protected dedicated time because test debt otherwise loses to features, and reviewed the results every quarter.
Open with
I would not start with a coverage target, because it spreads effort evenly over code that is not equally important. I would start by finding the data flows where errors are most expensive, using incidents and support tickets from the last year: payments, ledgers, inventory, order state.
Then, if they want more
For those flows I would require tests against the real database engine with real migrations, including concurrency tests that run two operations at once and check the invariant, and idempotency tests that replay messages. Most transactional bugs live in isolation, locking and flush behaviour, which mocks and H2 cannot show.
Then I would fund shared tooling through a platform team: Testcontainers setups with our database versions, data builders, and contract tests between services, so meeting the bar is cheap and consistent. I would make quality visible with a few measures: escaped data bugs by category, flaky tests, and build time, because slow or flaky suites get ignored.
I would agree dedicated capacity with product, something like 15 percent for two quarters for the critical teams, justified with the cost of past incidents, because otherwise test work always loses to features. And every quarter I would review the numbers with the leads and move investment to where bugs still escape.
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 Boot reference, Testing
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 company's core systems rely on transactional correctness, but test practices differ...": https://scrivio-interview-library.netlify.app/spring-boot/spring-boot-test/6325be6aee/