Scrivio Interview library
ScenarioPrincipal7 min read · updated 12 November 2026

You must choose between staying on a commercial database with proprietary sequences, features and licence fees, or moving 60 JPA services to an open-source database. How do you assess the exit cost and decide?

We assess the exit cost by first listing every proprietary feature the 60 services actually use: sequences and identity behaviour, stored procedures, query hints, special data types, native queries and tooling. JPA hides the simple differences but not native SQL, id generation or locking behaviour, so we estimate the effort per service including the testing needed to prove equivalence and performance. Then we compare licence and support costs over five to ten years with that migration cost and its risk, and if we move, we migrate in waves starting with low-risk services and keep a rollback path for each.

Why this question is asked

Database licence fees can be one of the largest lines in an infrastructure budget, and the promise that JPA makes us portable invites a quick decision either way. In reality, the portability is partial, and the true cost hides in the details each service grew over the years. Interviewers ask this at principal level to see whether we can turn a strategic question into an inventory, numbers and a staged plan. In this answer, we will build the inventory, see where JPA does and does not protect us, estimate per service, compare the costs over time, and lay out how to migrate safely if the numbers say so.

1Start With an Inventory, Not an Opinion

The first step is to find out what we really depend on. For each of the 60 services we collect the proprietary features in use. Some can be found by scanning code: native queries, vendor-specific hints in JPQL or annotations, calls to stored procedures, and mapping annotations for special types. Others live in the database: stored procedures, triggers, sequences with special settings, materialised views, partitioning, and vendor data types such as special date, XML or spatial types. And some live around the database: backup tooling, replication, monitoring, and reports that connect directly.

We would automate most of this with a script that searches repositories for createNativeQuery, @Query(nativeQuery = true), @Procedure and vendor hint names, and with queries against each database's catalogue for procedures, triggers and types. The result is a table with one row per service and a column per feature.

Java
// a few lines of the inventory output
// service native queries procedures vendor hints special types id generation
// order-service 14 3 2 1 vendor sequences
// catalog-service 0 0 0 0 sequences (standard)
// billing-service 61 22 9 4 sequences + triggers

2What JPA Hides and What It Does Not

JPA and Hibernate protect the plain part of the code well. JPQL and criteria queries are translated by the dialect, standard types map automatically, and paging, joins and most functions work on both engines. A service like catalog-service in the inventory above might move with little more than a driver and dialect change and a test run.

Several things are not hidden. Native queries are written in the vendor's SQL and must be rewritten and retested. Id generation differs: sequence semantics, identity columns and default increments vary, and a mismatch between allocationSize and the new sequences causes duplicate keys. Locking and isolation behave differently: the default isolation level, whether readers block writers, how SELECT FOR UPDATE with NOWAIT or SKIP LOCKED works, and what error code a deadlock or serialization failure produces. Empty strings and nulls, case sensitivity of comparisons, and timestamp precision can differ too. These behavioural differences are the dangerous ones, because the code compiles and most tests pass.

3Estimating Effort Per Service

With the inventory, we can put each service in a band. Services with no native SQL and standard types are small, perhaps a few days of work plus testing. Services with some native queries and a few procedures are medium. Services like billing-service, with 22 procedures and triggers that carry business logic, are large, because the logic must move into the application or be rewritten for the new engine.

The estimate must include proving equivalence, which is often the bigger part. We need integration tests for each repository against the new engine (Testcontainers makes that cheap), a comparison of query results on a copy of production data, and performance tests for the top queries, because a query plan that is fast on one engine can be slow on another. We would run a pilot on one small and one medium service first, then correct the estimates with real numbers before deciding.

Step throughFrom inventory to decision
  1. Inventory each servicenative SQL, procedures, hints, types, ids, tooling
  2. Classify into small, medium, large
  3. Pilot one small and one medium servicemeasure real effort and test cost
  4. Estimate total migration cost and risk
  5. Compare with 5 to 10 years of licence and support
  6. Savings clearly exceed cost and risk?
    Yesplan migration in wavesNostay, but reduce lock-in in new code

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

4Comparing the Costs Over Five to Ten Years

The comparison has to use the same horizon on both sides. Suppose licences and support cost 1.2 million a year. Over seven years that is 8.4 million, plus expected price increases. The migration might cost 60 services at an average of 25 person-days, plus a platform team for a year, plus parallel running of both databases during the transition, plus the new database's own costs: support contracts or managed service fees, training, and new tooling. If that totals 2.5 million, the case is strong. If billing-service alone needs a year of rewriting procedures, the numbers can change.

Risk belongs in the comparison too. A migration can cause outages, data errors or slower performance in the middle of the business year. We would put a value on that risk and on the opportunity cost, the features teams do not build while migrating. And we should check contract terms: renewal dates, whether licences can be reduced gradually as services move, and audit clauses.

5Migrating in Waves With a Rollback Path

If we decide to move, we migrate in waves. The first wave contains the small, low-risk services, which builds the tooling, the runbooks and the team's confidence. Later waves take medium services, and the large ones with stored logic come last, when we know the new engine best.

Each service needs a rollback path. For a cut-over, that means copying data with a tool that supports change data capture, so both databases stay in sync for a while, running the service against the new database while the old one is still current, and being able to switch back by configuration if errors or latency rise. Only when a service has run cleanly for an agreed period do we stop replication and decommission its old schema, and only when the last service has moved do the licence savings fully arrive.

6Reducing Lock-In Whatever We Decide

Even if we decide to stay, the inventory is valuable. We can set rules for new code, such as JPQL over native queries where reasonable, standard sequences with matching allocation sizes and no new business logic in stored procedures, so the exit cost stops growing. Then the next licence negotiation happens with a credible alternative, which is often worth money on its own.

7Follow-up questions

Does JPA make database migration easy?

It makes the plain part easy: entity mappings and JPQL are translated by the dialect. It does not cover native queries, stored procedures, vendor types, id generation details or locking and isolation behaviour, and those are where most of the cost and risk are.

How do we prove that a migrated service behaves the same?

With repository integration tests against the new engine, result comparisons on copies of production data, performance tests for the heaviest queries, and a period of running with replication and a switch back before the old database is turned off.

Why migrate the risky services last rather than first?

Because the first waves teach us the engine, the tooling and the failure modes cheaply. By the time we reach services with stored logic, we have tested runbooks and real estimates, and we can still decide to leave a few services on the old database if their cost does not justify the move.

8Conclusion

In this answer, we turned the question into an inventory of proprietary features per service, saw that JPA hides simple mapping and JPQL differences but not native queries, id generation or locking behaviour, and estimated effort per service including the testing to prove equivalence and performance. We compared licence and support over five to ten years with the migration cost and risk, and planned a migration in waves from low-risk services up, each with a rollback path, while limiting new lock-in whatever we decide.

What to say in the interviewAbout 90 seconds aloud

Open with

I would avoid deciding on opinion and start with an inventory. For each of the 60 services I would list what is actually proprietary: native queries, stored procedures and triggers, vendor hints, special data types, how ids are generated, and the tooling around the database like backups, replication and reports.

Then, if they want more

Much of that can be found automatically by scanning code for native queries and procedure calls and querying each database's catalogue. Then I would be honest about what JPA hides.

Entity mappings and JPQL move with a dialect change, but native SQL has to be rewritten, id generation and sequence semantics differ, and locking and isolation behave differently, which is dangerous because the code still compiles.

With that, I would classify services as small, medium or large, and pilot one small and one medium to get real numbers, including the cost of proving equivalence with integration tests on the new engine, result comparisons and performance tests.

Then I would compare licence and support costs over five to ten years with the migration cost, the new database's own costs, parallel running and the risk. If the savings clearly win, I would migrate in waves, low-risk services first, with change data capture keeping both databases in sync and a configuration switch to roll back each service. Either way, I would stop new lock-in in new code.

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 "You must choose between staying on a commercial database with proprietary sequences...": https://scrivio-interview-library.netlify.app/databases/jpa-fundamentals/1b26d3cbce/