Quick revision
The short answer
I would set a clear default: keep the database's READ COMMITTED and make concurrency control explicit per use case, with optimistic version columns, constraints and conditional updates. SERIALIZABLE is the tool for specific invariants that span rows, always with retries built in, not a blanket fix. To make the guidance stick, we document the known anomalies with examples from our own systems, provide shared retry helpers for serialization and deadlock errors, and monitor serialization failure and deadlock rates so we can see whether the approach is working.
What to remember
In this answer, we set organisation guidance for isolation. The default is the database's READ COMMITTED with explicit concurrency control per use case, version columns, constraints and conditional updates, and SERIALIZABLE is reserved for invariants across rows, used on every transaction that touches them and always with retries. We support the rule with documented anomalies from our own systems, a shared retry helper, and monitoring of serialization failure and deadlock rates.
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 set a clear default: keep the database's READ COMMITTED and make concurrency control explicit per use case, with optimistic version columns, constraints and conditional updates. SERIALIZABLE is the tool for specific invariants that span rows, always with retries built in, not a blanket fix. To make the guidance stick, we document the known anomalies with examples from our own systems, provide shared retry helpers for serialization and deadlock errors, and monitor serialization failure and deadlock rates so we can see whether the approach is working.
Why this question is asked
Inconsistent isolation choices are a symptom of a missing shared understanding. One team copies @Transactional(isolation = SERIALIZABLE) everywhere after a painful bug, another never thinks about it, and a third uses REPEATABLE READ because it sounded safer. Each choice has hidden consequences: aborted transactions without retries, lost updates, or lock contention. Interviewers ask a leadership question like this to see whether we can turn deep technical knowledge into guidance that many teams can follow without becoming experts. In this answer, we will look at why SERIALIZABLE everywhere is the wrong reaction, set the default, decide when SERIALIZABLE is right, and then cover documentation, shared tooling and monitoring.
1Why 'SERIALIZABLE Everywhere' Is the Wrong Reaction
After a write skew or lost update incident, SERIALIZABLE everywhere feels like the safe choice, and in one sense it is: it prevents every anomaly. But it changes the failure mode rather than removing failure. Under contention, PostgreSQL aborts transactions with SQLSTATE 40001, and InnoDB turns plain reads into locking reads that block writers. If the code has no retries, the bug becomes random errors for users. If it has retries everywhere, hot paths may spend much of their time redoing work.
It also hides the real lesson. The incident usually happened because a rule spanning rows had no protection, and the team did not recognise the pattern. A blanket setting does not teach anyone to recognise it next time, and it does not help when the same team moves to a database where SERIALIZABLE behaves differently.
2The Default: READ COMMITTED Plus Explicit Control
For most services, the guidance should be: keep the database's default, READ COMMITTED on PostgreSQL, and protect each use case's rules explicitly. Most rules fall into a few shapes with known tools. A single entity updated by several users needs optimistic locking with a version column, so the second writer gets an exception instead of overwriting. Uniqueness needs a unique constraint, never a check-then-insert. Counters and stock need conditional atomic updates such as UPDATE ... SET stock = stock - 1 WHERE stock > 0.
These tools are cheap, local and obvious in code review. The point of the guidance is that each use case states how it is protected, rather than relying on an isolation setting to do it invisibly.
3When SERIALIZABLE Is the Right Tool
SERIALIZABLE earns its place for invariants that span several rows and cannot easily be turned into one-row conflicts: 'at least one doctor on call', 'total allocations for a budget do not exceed the limit', 'no overlapping reservations' when an exclusion constraint does not fit. There, explicit locking gets complicated and easy to get wrong, and SERIALIZABLE protects the rule without listing every row.
The guidance should require three things when a team uses it: every transaction that touches the invariant uses SERIALIZABLE (one transaction at a lower level breaks the protection), retries are built in through the shared helper, and the transactions are short, so that a retry is cheap.
- Does the rule involve one row?YesVersion column or conditional updateNoGo on
- Is it uniqueness or a range overlap?YesUnique or exclusion constraintNoGo on
- Can the rule be stored in one row?YesMaterialise it and update that rowNoGo on
- SERIALIZABLE on every transaction for this rulewith the shared retry helper
4 steps in order. Play them, or step through them one at a time.
4Documenting Anomalies With Our Own Examples
Teams recognise patterns they have seen. I would write a short internal guide with one page per anomaly, lost update, write skew, phantom insert and non-repeatable read, each with a real example from our own domain, the two-session reproduction, how it would show up in production and which tool from the default list prevents it. Linking incidents to these pages in postmortems builds the shared vocabulary over time.
The guide should also cover the database differences that surprise people, such as InnoDB's REPEATABLE READ allowing lost updates where PostgreSQL's raises an error, because many organisations run both.
5Shared Retry Helpers and Monitoring
Retries are easy to get subtly wrong: retrying inside the transaction, retrying non-transient errors, or retrying forever. A shared library should offer one well-tested way, for example an annotation or a template that wraps the whole transactional call, retries ConcurrencyFailureException subclasses (serialization failures, deadlocks, optimistic lock failures) a few times with jittered backoff, and records a metric for each retry and each final failure.
Then we watch the numbers. Dashboards per service for serialization failures, deadlocks and optimistic lock conflicts, plus database-side metrics such as PostgreSQL's deadlock counter in pg_stat_database, show whether contention is rising. A sudden increase after a release points to a new hot spot; a steady zero on a service that uses SERIALIZABLE may mean the retries are hiding nothing, or that nobody is calling the code path, and both are worth knowing.
6Follow-up questions
Would you forbid SERIALIZABLE outside approved cases?
I would not forbid it, but I would ask for a short note in the code explaining the invariant it protects and confirming the retry helper is used. That keeps the decision visible in review without blocking teams that have a good reason.
How do you handle teams that already set it everywhere?
Measure first: retry and failure rates show the real cost. Then move use cases one at a time to the default with explicit control, keeping SERIALIZABLE where an invariant needs it, with tests that reproduce the anomaly so the change is safe.
Is optimistic locking enough for most web applications?
For entities edited by users, usually yes, because conflicts are rare and the user can be told to reload. For hot counters or rules across rows it is not, and that is where conditional updates, constraints or SERIALIZABLE come in.
7Conclusion
In this answer, we set organisation guidance for isolation. The default is the database's READ COMMITTED with explicit concurrency control per use case, version columns, constraints and conditional updates, and SERIALIZABLE is reserved for invariants across rows, used on every transaction that touches them and always with retries. We support the rule with documented anomalies from our own systems, a shared retry helper, and monitoring of serialization failure and deadlock rates.
Open with
I'd start by explaining why SERIALIZABLE everywhere isn't the fix. It prevents anomalies, but it turns them into aborted transactions or lock waits, and without retries users just see random errors; it also doesn't teach anyone to recognise the pattern that caused the bug.
Then, if they want more
So my default would be the database's READ COMMITTED with explicit concurrency control per use case. For a single entity edited concurrently, a version column. For uniqueness, a unique constraint, never check-then-insert. For counters and stock, a conditional atomic update. Those are cheap and visible in review.
SERIALIZABLE is the right tool for invariants across several rows that can't be turned into a one-row conflict, like at least one doctor on call or a budget limit across allocations, and then every transaction that touches that rule has to use it, with retries, and the transactions should be short.
To make this stick, I'd write a short guide with each anomaly, lost update, write skew, phantom insert, shown with an example from our own domain and the tool that prevents it, and link incidents to it. I'd provide one shared retry helper that wraps the whole transaction, retries concurrency failures a few times with jittered backoff and records metrics.
And I'd monitor serialization failures, deadlocks and optimistic lock conflicts per service, so we can see hot spots appearing after a release.
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 "Teams pick isolation levels inconsistently, and some set SERIALIZABLE everywhere after a...": https://scrivio-interview-library.netlify.app/databases/transactions/24609eec43/