Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Your engineering organisation has many Java developers who mostly use JPA and rarely write SQL, and production incidents often trace back to misunderstood SQL semantics. How would you raise SQL competence across 30 teams?

I would start from evidence, classifying past incidents to find the few SQL mistakes that keep recurring, then make the SQL that JPA generates visible in development and in code review. Teaching should use the teams' own queries and plans in short sessions, carried by a database champion in each team and a guild with office hours. Guardrails such as statement timeouts, query linting and slow-query dashboards per owning service catch what training misses.

Why this question is asked

When most developers meet the database only through JPA, SQL becomes something that happens to them rather than something they write. The result is a familiar list of incidents: a report that drops customers, a page that runs 300 queries, a delete that locks a table. Interviewers ask this leadership question at senior levels because the fix is not a single course; it is a change in how an organisation sees and reviews its database work, across teams that each have their own priorities. In this answer, we will walk through how a senior engineer reasons about it: finding the real failure patterns, making SQL visible, teaching in a way that sticks, spreading ownership through champions, adding guardrails, and measuring whether any of it worked.

1Start From the Incidents, Not From a Curriculum

The first instinct is to schedule an SQL course for everyone. It feels productive, but a generic course teaches what the trainer knows rather than what our teams get wrong, and 30 teams sitting through it costs thousands of engineering hours. The better first step is cheap: read the last year or two of incident reports and postmortems that involve the database and classify the root causes.

In most Java organisations the list is short and repetitive. Typical entries are NULL handling, such as NOT IN with a subquery that contains a NULL and returns nothing; outer joins filtered in WHERE that silently drop rows; pagination without a tiebreaker in ORDER BY, so pages repeat or skip rows; N+1 queries, where loading a list issues one extra query per element through lazy loading; and unbounded UPDATE or DELETE statements that lock or rewrite far more rows than intended. If five patterns explain 70 percent of incidents, those five are the programme.

Example classification of 40 database incidents
PatternIncidentsTypical symptom
N+1 queries from lazy loading11slow page, connection pool exhausted
NULL semantics (NOT IN, <> NULL)7missing rows in a report
Outer join filtered in WHERE6customers vanish from exports
Unbounded UPDATE / DELETE5table locked, replication lag
Pagination without tiebreaker4duplicate or skipped items
Other7various
Illustrative numbers: a few patterns usually explain most incidents.

2Make the Generated SQL Visible

Developers cannot reason about SQL they never see. JPA hides it by design, so the second step is to put it back in front of people during normal work. In development profiles we turn on SQL logging with bind parameters, through Hibernate's SQL logging categories or a tool such as p6spy or datasource-proxy, and enable Hibernate statistics so each request reports how many statements it ran. A test helper that asserts the number of statements for a key endpoint turns an N+1 regression into a failing test instead of an incident.

Code review is the other place. Reviews today check the Java and skip the query, because the query is not in the diff. We ask authors of repository changes to paste the generated SQL and, for anything touching a large table, the EXPLAIN output into the pull request. That one habit spreads knowledge faster than any course, because every reviewer sees real plans every week.

3Teach With the Teams' Own Queries

When we do teach, we use material from our own systems: the query from last month's incident, its plan, and the fix. Sessions are short, 45 minutes, and focused on one pattern each, such as how NULL behaves in comparisons or how to read an EXPLAIN plan. People remember a bug they recognise from their own codebase far better than a textbook example.

We back the sessions with a small set of practice exercises against a copy of a realistic schema, with answers checked automatically. The exercises target the incident patterns: write the report that keeps customers without orders, fix the pagination query, find the N+1 in this service. They are optional, but champions use them with new joiners.

4Spread Ownership Through Champions and a Guild

A central database team cannot review 30 teams' queries; it would become a bottleneck within a month. So we ask each team to name a database champion, someone interested, not necessarily the most senior. Champions get deeper training, meet every two weeks in a database guild, and are the first reviewers for risky queries in their team. The central experts hold weekly office hours where anyone can bring a slow query or a plan they do not understand.

The cost is real, roughly 10 percent of a champion's time, so it needs explicit support from engineering managers. In return, knowledge spreads sideways through people who know each team's code, and the guild becomes the place where a new rule, for example always using a tiebreaker in paginated queries, gets agreed and carried back.

Step throughHow the programme fits together
  1. Classify past incidentsfind the recurring patterns
  2. Make SQL visiblelogging, statement counts, SQL in pull requests
  3. Teach with own examplesshort sessions, practice exercises
  4. Champions and guildone per team, office hours
  5. Guardrailstimeouts, linting, dashboards per owner
  6. Measure and adjustrepeat incidents, slow queries per service

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

5Add Guardrails for What Training Misses

Even well-trained people make mistakes at 6 pm on a Friday, so we add automatic limits. A statement timeout per service, for example statement_timeout set to a few seconds for the web application role in PostgreSQL, stops a runaway query before it holds locks for minutes. A lock timeout does the same for migrations. Query linting in the build, with a tool such as SQLFluff or custom checks on migration files, flags patterns like DELETE without WHERE or a NOT IN subquery. Migrations that touch large tables go through a checklist.

Finally, every service owner gets a dashboard of its slowest and most frequent statements, from pg_stat_statements in PostgreSQL or the performance schema in MySQL. Ownership matters here: a global slow-query report that nobody owns is ignored, while a team that sees its own top five queries every sprint fixes them.

6Measuring Whether It Worked

We set a few measures before starting, so we can tell whether the effort pays off: the number of incidents caused by the known patterns per quarter, the count of statements over one second per service, the share of repository pull requests that include SQL or plans, and how many teams have an active champion. A reasonable target is halving repeat-pattern incidents within two or three quarters. If a pattern keeps recurring despite training, that is a sign it needs a guardrail or a library change instead of more teaching.

7Follow-up questions

What if teams say they have no time for this?

Show them the cost of their own incidents in hours and customer impact, and start with changes that cost almost nothing, such as SQL logging in development and statement-count tests. Champions' time should be agreed with managers as part of the team's plan, not taken from evenings.

Should developers stop using JPA and write SQL directly?

No. JPA is productive for most write paths and simple reads. The goal is that developers understand the SQL it generates and know when to use a native query, a projection or a different fetch strategy. Reports and complex reads often belong in hand-written SQL, and that is a judgement we want people able to make.

How do you keep the programme alive after the first enthusiasm?

Tie it to recurring work: incident reviews feed new examples, the guild meets on a fixed schedule, dashboards are part of each team's sprint review, and new joiners take the exercises during onboarding.

8Conclusion

In this answer, we treated raising SQL competence as an organisational change rather than a course. We started from incident data to find the few patterns that matter, made generated SQL visible in development and code review, taught with the teams' own queries, spread ownership through champions and a guild, added guardrails such as timeouts, linting and per-owner dashboards, and agreed measures to know whether incidents actually went down.

What to say in the interviewAbout 80 seconds aloud

Open with

I would not start with a company-wide SQL course. I would start by classifying the database incidents from the last year or two, because in my experience a handful of patterns explain most of them: NULL handling, outer joins filtered in WHERE, pagination without a tiebreaker, N+1 queries from lazy loading, and unbounded updates or deletes.

Then, if they want more

Those patterns become the programme. Next I would make SQL visible, because JPA hides it: SQL logging with parameters and Hibernate statistics in development, statement-count assertions in tests for key endpoints, and a review norm that repository changes include the generated SQL and, for big tables, the plan.

Teaching would use our own incidents and plans, in short sessions per pattern with practice exercises. To scale across 30 teams, each team names a database champion who gets deeper training and joins a guild, and the central experts run office hours, so the central team is not a bottleneck.

Then guardrails for what training misses: statement and lock timeouts per service, linting on queries and migrations, and slow-query dashboards owned by each service team. I would measure repeat-pattern incidents and slow statements per service, aim to halve the incidents in a few quarters, and turn any pattern that keeps recurring into a guardrail rather than more training.

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 "Your engineering organisation has many Java developers who mostly use JPA and rarely...": https://scrivio-interview-library.netlify.app/databases/sql-fundamentals/123a92fc10/