Quick revision
The short answer
I would treat this as a learning-system problem, not a database problem. Turn past incidents into a short guide of the few patterns that caused our outages, with our own code; build guard rails into the platform so the safe behaviour is the default (lock and statement timeouts, transaction duration metrics, alerts on long transactions); add data access review to design reviews for changes that touch hot tables; train with realistic hands-on exercises; and give a database reliability group the mandate to set standards and help teams, measured by lock-related incidents over time.
What to remember
In this answer, we saw that locking problems repeat because the risky code looks fine, works in testing and the lessons stay with one team. We change that with a short guide of our own incident patterns, platform defaults for lock, statement and idle-in-transaction timeouts plus transaction duration metrics and alerts, data access questions in design reviews, hands-on exercises that reproduce real failures, and a database reliability group whose success is measured by lock-related incidents over time.
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 treat this as a learning-system problem, not a database problem. Turn past incidents into a short guide of the few patterns that caused our outages, with our own code; build guard rails into the platform so the safe behaviour is the default (lock and statement timeouts, transaction duration metrics, alerts on long transactions); add data access review to design reviews for changes that touch hot tables; train with realistic hands-on exercises; and give a database reliability group the mandate to set standards and help teams, measured by lock-related incidents over time.
Why this question is asked
When the same three mistakes cause outages in team after team, the problem is no longer technical knowledge in general; it is how that knowledge reaches the people writing the next feature. Interviewers ask this at the most senior levels to see whether a candidate can change an organisation's habits, not just fix the latest incident. In this answer, we will look at why these problems repeat, then go through five changes: a guide built from our own incidents, platform guard rails, design review, realistic training, and an owning group with a measurable goal.
1Why the Same Problems Keep Repeating
Long transactions, remote calls inside transactions and missing indexes all share one property: the code looks fine and works in development. A @Transactional method that calls an HTTP service passes every test, because tests have no contention. A query without an index is fast on a test table of 500 rows. The problem only appears under production load, often months later, and in a different team from the one that learned the lesson last time.
Postmortems usually produce local fixes and a document few people read. So the knowledge stays with the team that had the incident, and the platform keeps allowing the same pattern by default. To stop the repetition we need to change three things at once: what people know, what the platform allows, and when the design gets a second look.
2A Short Guide Built From Our Own Incidents
Generic database advice is easy to ignore. A short guide, a few pages long, built from our own outages is not. It should cover the five patterns that caused most of our lock incidents, for example a remote call inside a transaction, a long batch transaction, a missing index on an UPDATE filter, inconsistent lock order, and DDL waiting behind a long transaction and blocking everyone queued after it. For each pattern, it shows the real code from our system (simplified), the incident it caused with its impact, how to detect it, and the fixed version.
The guide is linked from postmortems, onboarding and design templates. When a new incident shows a new pattern, the guide gets a new entry. Keeping it short matters more than keeping it complete: people read five patterns, nobody reads fifty.
3Guard Rails in the Platform
The most reliable way to change behaviour is to make the safe option the default. The shared Spring Boot starter can set sensible database session defaults for every service: a lock_timeout of a few seconds, a statement_timeout aligned with request timeouts, and idle_in_transaction_session_timeout so a forgotten open transaction is ended. Teams can raise them for specific jobs, but they have to do it on purpose.
- Guide from our incidentswhat people know: five patterns, our own code
- Design reviewa second look before hot tables change
- Platform defaultstimeouts and metrics every service gets
- Monitoring and alertslong transactions and lock waits seen early
- Database reliability groupowns the standards, helps teams, tracks incidents
5 layers, from the top down. Step through them one at a time.
The starter also publishes a metric for transaction duration, for example a timer around every transaction with the method name as a tag, and the platform alerts when a service's p99 transaction time exceeds a threshold or when the database shows a transaction open longer than a minute. A long transaction is the common cause behind most lock incidents, so seeing them early prevents most outages. Combining several SET commands in connection-init-sql depends on the driver accepting multiple statements; one option per role (ALTER ROLE app SET ...) avoids that question.
4Data Access Review and Realistic Training
Design reviews already look at APIs and services; they should also look at data access for features that change hot rows or busy tables. The questions are few and concrete: what does each transaction lock, how long can it last, does it call anything remote, which index serves each UPDATE and DELETE, and what happens with ten concurrent requests on the same row. Reviewers from the database group join when the feature touches one of the known hot tables.
Training works best when people see the failure happen. A two-hour workshop in a test environment where engineers reproduce a deadlock between two sessions, watch a lock queue form behind an ALTER TABLE waiting on a long transaction, and see a connection pool drain when a remote call sits inside a transaction, sticks far better than slides. Each exercise ends with the fix and with the query that shows the problem in production.
5An Owning Group With a Measurable Goal
All of this decays unless someone owns it. A small database reliability group, a few engineers with deep database knowledge, gets the mandate to set the standards, maintain the guide and platform defaults, join reviews of risky changes, and help teams during and after incidents. Its job is to make other teams better, not to become a gate every change must pass.
Its success is measured by outcomes: the number and impact of lock-related incidents per quarter, the count of services with transactions over a minute, and adoption of the platform defaults. If the incident count falls over a year while the number of services grows, the learning system is working.
6Follow-up questions
How do you get teams to adopt platform defaults without breaking existing services?
Roll them out in observe mode first: measure how many requests would have hit the new timeouts, share the list with each team, and give a date. Services that need longer limits for specific jobs declare them explicitly. New services get the defaults from day one, and existing ones move over as their findings are fixed.
Is a central database group a bottleneck?
It becomes one if every change needs its approval. The model that works is enabling: the group writes standards and tools, reviews only changes that touch known hot tables or high-risk patterns, and teaches, so most teams handle most changes themselves.
What should a lock-related postmortem produce?
Beyond the local fix, it should answer whether the guide already covered this pattern and, if so, why it was missed, and whether a platform default or check could have prevented it. The answers turn into a guide entry, a default or a review question, so the next team benefits.
7Conclusion
In this answer, we saw that locking problems repeat because the risky code looks fine, works in testing and the lessons stay with one team. We change that with a short guide of our own incident patterns, platform defaults for lock, statement and idle-in-transaction timeouts plus transaction duration metrics and alerts, data access questions in design reviews, hands-on exercises that reproduce real failures, and a database reliability group whose success is measured by lock-related incidents over time.
Open with
I'd treat it as a problem of how we learn, because the patterns are well known and still repeat: long transactions, remote calls inside them, missing indexes. They look fine in code review and pass tests, and the lesson stays with whichever team got burned.
Then, if they want more
First I'd turn our incidents into a short guide, five patterns, each with our own code, the incident it caused, how to spot it and the fix, linked from postmortems and onboarding.
Second, guard rails in the platform: the shared Spring Boot starter sets lock_timeout, statement_timeout and idle_in_transaction_session_timeout by default, records transaction duration, and we alert on transactions open longer than a minute. That makes the safe path the default.
Third, design reviews for features that touch hot tables include data access questions: what does each transaction lock, how long, any remote calls, which index serves each update. Fourth, hands-on training where engineers reproduce a deadlock and a DDL lock queue themselves.
And finally, a small database reliability group owns the standards and helps teams, and I'd measure it by lock-related incidents per quarter going down while the number of services grows.
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
- PostgreSQL documentation, MySQL reference manual
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 "Most locking problems your company has suffered came from application design, not from...": https://scrivio-interview-library.netlify.app/databases/database-locking/94f1b2a58f/