Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Performance problems from ORM usage (N+1, over-fetching, chatty sessions) appear in most of your services years after launch. Is this an argument to move away from ORMs as an organisation, or to invest in using them better? How would you decide?

I would not decide by opinion. The same problems appear with hand-written SQL called in loops, so the root cause is usually missing data-access discipline rather than the ORM. I would compare the total cost, delivery speed with JPA against time lost to performance incidents, invest first in guardrails such as statement-count tests, query metrics, training and reviewed fetch plans, allow SQL-first tools for read-heavy and reporting paths, and revisit the decision with our own data after the guardrails have been in place for a while.

Why this question is asked

When the same kind of incident appears in most services, it is tempting to blame the shared tool, and an ORM is an easy target: it generates SQL nobody wrote, and its problems are well known. But switching the data access technology of many services is one of the most expensive changes an organisation can make, and if it does not address the real cause, the incidents come back in a new form. Interviewers ask this leadership question to see how we make a large technical decision under uncertainty. In this answer, we will look at what the problems actually are, compare the costs honestly, describe the guardrails I would try first, explain where SQL-first tools fit, and set out how to decide with data.

1What the Problems Really Are

N+1 means loading a list and then one item at a time for each element. Over-fetching means loading far more data than the use case needs, such as whole entity graphs for a list of names. Chatty sessions mean many small round trips where one query would do. Each of these is a data access pattern, and each can be written without an ORM.

A JDBC or jOOQ codebase where a service method calls customerDao.findById inside a loop has exactly the same N+1. A hand-written select * from customer in a report has the same over-fetching. The ORM makes these patterns easier to write by accident, because a getter hides a query, but it also offers the tools to avoid them, fetch joins, entity graphs, batch fetching and projections. So the first question is not which tool, but why our teams do not see what queries their code runs.

2Comparing the Total Cost

A fair comparison looks at the whole cost, not only at incidents. JPA gives delivery speed: mapping, dirty checking, which means detecting changed fields and writing them automatically, optimistic locking and simple CRUD with little code. Moving away costs that speed on every feature, plus the migration itself across many services, plus retraining. Staying costs the incidents and the time teams spend investigating them.

Rough numbers make the trade-off concrete. If ORM-related incidents cost us 15 engineer-days per quarter across the organisation, and migrating one service to a SQL-first tool takes 40 engineer-days, migrating 20 services costs 800 days, the equivalent of more than thirteen years of current incident cost, before counting slower feature delivery. If guardrails cut incidents by half for 60 days of work, they pay back in about two years and keep paying after that. These are illustrative numbers, but this is the calculation to make with our own.

Options and their costs
OptionUpfront costOngoing costAddresses root cause?
Keep JPA as isnoneincidents continueno
JPA plus guardrailstests, metrics, traininglow, part of normal workyes, discipline
Mixed: JPA plus SQL-first readsper path, gradualtwo tools to knowyes, for read paths
Replace ORM everywherelarge migrationslower CRUD featuresonly if discipline follows

3Investing in Guardrails First

The guardrails target the real cause, that teams cannot see their queries. Statement-count tests on the key use cases make N+1 and chatty patterns fail the build. Query metrics, statements per request in traces and slow query reports per service, make problems visible in production before customers notice. A short training, two hours on fetch plans, proxies and projections with examples from our own code, gives every developer the vocabulary. And reviewed fetch plans, a checklist item asking how each new query loads its associations, makes the question part of normal review.

A shared starter library helps too: lazy associations by default, open session in view disabled, a sensible global batch fetch size, and statement counting available in tests. Each team gets the defaults without having to discover them.

4Where SQL-First Tools Fit

Some paths are a poor fit for an ORM in any organisation: reports that aggregate across many tables, search screens with dynamic filters and sorting, exports of millions of rows, and analytics queries. For these, a SQL-first tool such as jOOQ, Spring's JdbcClient or plain SQL with a row mapper is clearer and faster, and the SQL can be tuned directly. Allowing them for read-heavy and reporting paths, inside the same service and transaction management, gives teams the right tool without a migration.

So the target is often a mixed model: JPA for the write side, where aggregates are loaded, changed and saved, and SQL-first queries for the read side where shape and performance matter most. That is a much smaller change than replacing the ORM, and it removes the paths that cause the worst incidents.

Step throughChoosing the tool for a new data access path
  1. Loads and changes an aggregate?e.g. place order, update profile
    YesJPA with a reviewed fetch planNoCheck read shape
  2. Report, export or complex search?
    YesSQL-first tool such as jOOQ or JdbcClientNoJPA DTO projection
  3. Add a statement-count testfor either choice

3 steps in order. Play them, or step through them one at a time.

5Deciding With Our Own Data

I would put the guardrails in place, then measure for two or three quarters: ORM-related incidents per quarter, statements per request on the top endpoints, and how much time teams spend on data access problems. If incidents fall clearly, the decision is made: we invest in using the ORM better. If they do not fall, even with tests and metrics in place, the data then supports a deeper change, and we will know which services and which kinds of paths hurt most, so any migration can start there rather than everywhere.

Revisiting the decision with data also keeps the conversation honest. Teams that prefer SQL get a fair hearing and a place to use it, and teams that rely on JPA see that their productivity was part of the calculation.

6Follow-up questions

What if a team strongly wants to drop JPA for its service?

I would ask for the same evidence: what problems they have, what the guardrails changed, and what the migration costs. If a service is mostly reporting and search, moving it to SQL-first may well be right, and the mixed model allows it. What I would avoid is a decision driven by preference that the team later has to maintain alone.

Isn't the ORM's abstraction the real problem, since it hides SQL?

It hides SQL from people who do not look, but it does not prevent looking. With SQL logging, statement counts and explicit fetch plans, the generated SQL is as visible as hand-written SQL. The discipline of checking what runs is needed with any tool.

How do you train many teams without slowing them down?

Short, concrete sessions using real examples from their own services, a small set of patterns in the shared documentation, and pairing on the first fix. The statement-count tests then teach continuously, because each failure shows exactly which query pattern went wrong.

7Conclusion

In this answer, we saw that N+1, over-fetching and chatty sessions are data access patterns that occur with hand-written SQL too, so the root cause is usually missing discipline. We compared total costs, invested first in guardrails, statement-count tests, query metrics, training and reviewed fetch plans, allowed SQL-first tools for read-heavy and reporting paths, and planned to revisit the decision with our own measurements.

What to say in the interviewAbout 90 seconds aloud

Open with

I would not treat it as an ORM-or-no-ORM question at first, because the same problems appear without an ORM. A DAO call inside a loop is an N+1 in plain JDBC too, and a select star is over-fetching in any tool.

Then, if they want more

The ORM makes those patterns easier to write by accident, but the root cause is that teams do not see what queries their code runs. So I would compare total cost: the delivery speed JPA gives us on CRUD-heavy work against the time spent on performance incidents, and against the very large cost of migrating many services.

Usually guardrails win first. That means statement-count tests on key use cases, query metrics per request in production, a short training on fetch plans, proxies and projections, fetch plans reviewed in code review, and a shared starter with lazy defaults, open session in view off and a batch fetch size.

At the same time, I would allow SQL-first tools like jOOQ or JdbcClient for reports, exports and complex searches, where they are simply the better fit, so we get a mixed model rather than a migration. Then I would measure incidents and statements per request for a few quarters.

If the problems fall, we invest in using JPA well; if they do not, we have the data to choose where a deeper change should start.

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.
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 "Performance problems from ORM usage (N+1, over-fetching, chatty sessions) appear in most...": https://scrivio-interview-library.netlify.app/databases/jpa-performance/f2ffcfb66b/