Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

Your company is migrating 25 services from MySQL 8.4 to PostgreSQL 17. Code reviews show that teams never set isolation explicitly. Which behaviour changes do you expect because of different isolation defaults and locking, and how do you manage the risk?

Because nobody set isolation explicitly, every service silently drops from InnoDB's REPEATABLE READ to PostgreSQL's READ COMMITTED, so repeated reads in one transaction can now see newer data. InnoDB's gap and next-key locks disappear, so a SELECT ... FOR UPDATE on an empty range no longer blocks concurrent inserts, and in PostgreSQL any error aborts the whole transaction, so catch-and-continue code breaks. I would manage this by inventorying the risky patterns, adding concurrency tests against both databases, running shadow traffic before cut-over, and deciding per service whether to set REPEATABLE READ explicitly.

Why this question is asked

Database migrations are usually planned around schemas, data types and SQL syntax. The concurrency behaviour changes quietly, and that is where the dangerous bugs hide: they do not fail tests, they show up weeks later as duplicates or inconsistent reports. With 25 services and no explicit isolation anywhere, every service is affected. Interviewers ask this to see whether we can predict those changes and turn them into a manageable plan. In this answer, we will go through the three behaviour changes, then the inventory, testing and cut-over plan, and the per-service decision about isolation.

1Change 1: REPEATABLE READ Becomes READ COMMITTED

An isolation level controls how much a transaction sees of other transactions' changes. MySQL InnoDB defaults to REPEATABLE READ: within a transaction, plain SELECTs all read from the snapshot taken by the first one. PostgreSQL defaults to READ COMMITTED: each statement sees everything committed before it started. Since the services never set a level, they inherit the new default.

So code that reads the same data twice and assumes it has not changed now behaves differently. A report that sums order lines and then reads the order totals may see an order that was added between the two queries, and the totals no longer match. A method that reads a status, does some work, and reads it again to decide may see a new status the second time.

What changes when the services move
BehaviourMySQL 8.4 InnoDBPostgreSQL 17
Default isolationREPEATABLE READREAD COMMITTED
Two SELECTs in one transactionsame snapshoteach sees latest committed data
FOR UPDATE on a missing rangegap lock blocks insertslocks nothing, inserts proceed
Error in one statementstatement rolled back, transaction goes onwhole transaction aborted
Duplicate key upsertON DUPLICATE KEY UPDATEON CONFLICT ... DO UPDATE

2Change 2: Gap and Next-Key Locks Disappear

In InnoDB at REPEATABLE READ, a locking read locks not only the rows it finds but also the gaps between index entries, using gap locks and next-key locks. So a query that finds nothing still blocks other transactions from inserting into that range. Some code relies on this, sometimes without knowing it.

Java
-- the 'check then insert' many MySQL services rely on
BEGIN;
SELECT id FROM booking WHERE room_id = 5 AND day = '2026-12-01' FOR UPDATE; -- 0 rows
INSERT INTO booking (room_id, day, guest) VALUES (5, '2026-12-01', 'Ana');
COMMIT;
-- MySQL InnoDB RR: the empty range is gap-locked, a second session waits (or deadlocks), no double booking
-- PostgreSQL: no rows means nothing is locked; both sessions insert -> double booking

PostgreSQL has no gap locks. FOR UPDATE locks only rows that exist. The phantom, the new row the check did not see, gets in. The fix is to state the rule in the schema, here a unique constraint on (room_id, day) so the second insert fails, or an exclusion constraint for overlapping ranges, or to run that transaction at SERIALIZABLE, where PostgreSQL detects the conflict and aborts one.

3Change 3: Any Error Aborts the Whole Transaction

In MySQL, when a statement fails with, say, a duplicate key, InnoDB rolls back that statement and the transaction continues. Code that catches the exception and carries on works. In PostgreSQL, the first error puts the transaction into an aborted state: every following statement fails with current transaction is aborted, commands ignored until end of transaction block, and COMMIT turns into ROLLBACK. Catch-and-continue code must change to use INSERT ... ON CONFLICT, which avoids the error, or a savepoint around the risky statement. Spring's Propagation.NESTED creates such savepoints for JDBC code.

4Managing the Risk: Inventory, Tests and Shadow Traffic

The first step is an inventory across all 25 services with code search: FOR UPDATE and LOCK IN SHARE MODE, which may rely on gap locks; catch blocks around DataIntegrityViolationException or DuplicateKeyException that continue inside a transaction; read-then-write and read-twice patterns in @Transactional methods; and native queries with MySQL-specific syntax. Each hit gets an owner and a decision.

The second step is concurrency tests for the risky paths, run with Testcontainers against both MySQL 8.4 and PostgreSQL 17. Two transactions synchronised with a latch run the check-then-insert at the same moment; the test passes on MySQL and, until fixed, fails on PostgreSQL, which proves the test sees the difference. The third step is shadow traffic before cut-over: production requests are replayed against the PostgreSQL stack, and results, error rates and invariants, such as no duplicate bookings, are compared with the MySQL side.

Step throughMigration risk plan per service
  1. Inventory risky patternsFOR UPDATE, catch-and-continue, read-then-write, MySQL SQL
  2. Write latch-based concurrency testsTestcontainers, both databases
  3. Fix with constraints, ON CONFLICT, savepoints
  4. Does the service rely on RR semantics?
    YesSet REPEATABLE READ explicitlyNoStay on READ COMMITTED
  5. Shadow traffic and invariant checkscompare with MySQL
  6. Cut over, keep reconciliation queries

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

5Deciding the Isolation Level per Service

Some services will be simpler to move if they keep closer semantics. Setting REPEATABLE READ explicitly in PostgreSQL gives them one snapshot per transaction, like InnoDB for plain reads. But it is not identical: PostgreSQL's REPEATABLE READ raises serialization errors (SQLSTATE 40001) when a transaction updates a row changed after its snapshot, where InnoDB would just update the latest version. So a service that sets it also needs retry handling. Others are fine at READ COMMITTED after the fixes above. Each service records its choice and the reasoning in its design document, so the next engineer knows the level was chosen rather than inherited.

6Follow-up questions

Which MySQL-specific SQL also needs rewriting?

INSERT ... ON DUPLICATE KEY UPDATE becomes INSERT ... ON CONFLICT (...) DO UPDATE; REPLACE INTO has no direct equivalent and is usually rewritten the same way. Backtick-quoted identifiers become double quotes or unquoted names. AUTO_INCREMENT becomes an identity column. LIMIT on UPDATE and DELETE is not supported in PostgreSQL and needs a subquery on the key. Functions differ: IFNULL becomes COALESCE, GROUP_CONCAT becomes string_agg. MySQL's lenient GROUP BY, zero dates, implicit type conversions and case-insensitive default collations behave differently, so queries that compared strings without regard to case may now miss rows. TINYINT(1) used as a boolean becomes boolean.

Would SERIALIZABLE in PostgreSQL replace the gap locks?

For the protected transactions, yes, and more completely, since it also detects write skew. It needs retries on 40001, so it suits the few transactions that need it rather than all 25 services by default.

Does Hibernate hide these differences?

No. Hibernate generates dialect-correct SQL, but isolation, locking and error handling come from the database, so the same entity code behaves differently.

7Conclusion

In this answer, we saw three behaviour changes in a MySQL to PostgreSQL migration when isolation is never set: the default drops from REPEATABLE READ to READ COMMITTED, gap and next-key locks vanish so empty-range FOR UPDATE checks let phantoms in, and any error aborts the whole PostgreSQL transaction. We manage the risk with a code inventory of risky patterns, concurrency tests on both databases with Testcontainers, fixes using constraints, ON CONFLICT and savepoints, shadow traffic before cut-over, and a documented per-service decision on whether to set REPEATABLE READ.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd expect three behaviour changes. First, the default isolation drops from InnoDB's REPEATABLE READ to PostgreSQL's READ COMMITTED, because nobody set it explicitly. So code that reads the same data twice in a transaction, like a report or a check-then-act, can now see newer data the second time.

Then, if they want more

Second, gap and next-key locks disappear. In MySQL, a select for update on a range that finds nothing still blocks other inserts into that range, and some booking-style code relies on that. In PostgreSQL it locks nothing, so both transactions insert and you get duplicates. The fix is a unique or exclusion constraint, or SERIALIZABLE for that transaction.

Third, in PostgreSQL any error aborts the whole transaction, while MySQL just rolls back the failed statement, so catch-and-continue code breaks and needs ON CONFLICT or a savepoint. To manage it, I'd inventory all 25 services with code search for FOR UPDATE, catch-and-continue around duplicate keys, read-then-write patterns and MySQL-specific SQL.

I'd write latch-based concurrency tests with Testcontainers against both databases for the risky paths, and run shadow traffic with invariant checks before cut-over. Then for each service I'd decide whether to set REPEATABLE READ explicitly, knowing PostgreSQL's version raises serialization errors that need retries, and document that choice.

About this answer

Last updated
12 November 2026
Versions it names
MySQL 8.4, PostgreSQL 17
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 "Your company is migrating 25 services from MySQL 8.4 to PostgreSQL 17. Code reviews show...": https://scrivio-interview-library.netlify.app/databases/acid-and-isolation/ca983e5a3f/