Scrivio Interview library
LeadershipAdvanced7 min read · updated 12 November 2026

Contention problems in your organisation are usually found only during incidents. What would you put in place so they are found earlier?

I would move contention detection from incidents to the normal development cycle by putting five things in place: load tests in CI or pre-production that run at production-like concurrency, continuous JFR or a continuous profiler in production with lock views, lock wait time and pool saturation tracked as service-level metrics with alerts, a contention review in design reviews whenever shared state sits on a hot path, and shared incident write-ups so teams learn the common patterns. Each catches what the earlier one misses, and together they make contention visible weeks before it becomes an outage.

Why this question is asked

Contention problems have an unpleasant property: they are invisible at low load and appear suddenly when traffic crosses a threshold. A lock that costs nothing at 50 requests per second can queue every thread at 400. So organisations that only test functionally and only profile during incidents will keep meeting these problems at the worst possible time. Interviewers ask this leadership question to see whether we can design a system of practices rather than heroics. In this answer, we will see why contention escapes normal testing, then build the five practices in the order a change flows from design to production, and finish with how to roll them out without overloading teams.

1Why Contention Escapes Normal Testing

Unit and integration tests run one request at a time, so a lock is never contended. Functional end-to-end tests run a few concurrent users at most. Contention depends on how many threads compete for the same lock at the same moment, which grows with traffic, and the waiting time grows faster than linearly once the lock is busy more than about half the time. That is basic queueing behaviour: a lock held 2 ms per request is idle most of the time at 50 requests per second, but at 400 requests per second it is needed for 800 ms of every second, and queues form fast.

So a practice that finds contention must either create production-like concurrency before release, or observe real concurrency in production continuously. The plan below does both, from both ends of the lifecycle.

Where each practice catches contention
PracticeWhen it catches itWhat it costs
Contention question in design reviewBefore code is writtenReviewer time
Load tests at production concurrencyBefore releaseTest environment, scripts
Continuous JFR or profiler with lock viewsRight after release, before users noticeAgent overhead, storage
Lock wait and pool saturation alertsWhen it starts to hurtInstrumentation, alert tuning
Shared incident write-upsNext time, in another teamWriting and a review forum

2Load Tests That Look Like Production

The highest-value step is a load test that reaches the concurrency of a busy production hour, run automatically for services on the critical path. Not every pull request needs it; a nightly run in pre-production and a run before each release is a good balance. The test should use realistic data, since contention often depends on hot keys, for example one very large tenant, and it should run with production-like pool sizes and instance counts.

The key is what we measure. A test that reports only average latency will miss contention. We record p99, throughput and, through JFR in the test JVMs, total lock wait time per lock class, and compare each run with the previous one. A release that doubles the lock wait on one class gets flagged even if latency still meets the target, because it will not meet it at next season's traffic.

3Continuous JFR or Profiling in Production

Load tests never perfectly match production. So we also observe production all the time. JFR, built into the JDK and running at around one percent overhead with the default profile, records monitor enter and park events above a threshold in every JVM. With a continuous profiler on top, which samples lock and wall-clock profiles and uploads them every minute, we can compare a new release with the previous one and see a lock that got hotter, even if nobody has complained yet.

This turns a contention regression from an incident into a ticket: the profiler shows that release 5.3 added 40 ms of lock waiting to checkout requests on one class, and the owning team fixes it during the week.

4Lock Wait Time and Pool Saturation as Service Metrics

What gets measured and alerted on gets attention. Alongside latency and errors, each important service publishes how saturated its shared resources are: connection pool pending threads and acquire time, executor queue depth and active threads, and, where the code has known hot locks, the time spent waiting for them. Micrometer already provides many of these for Hikari and Spring's executors. We set alerts on saturation trends, for example pool pending above zero for more than five minutes, so the warning arrives while there is still headroom.

Java
// A hot lock made visible as a metric
private final ReentrantLock lock = new ReentrantLock();
private final Timer lockWait = Timer.builder("ratetable.lock.wait").register(registry);
BigDecimal rate(String ccy) {
long start = System.nanoTime();
lock.lock();
lockWait.record(System.nanoTime() - start, TimeUnit.NANOSECONDS); // p99 of waiting, per instance
try { return rates.get(ccy); } finally { lock.unlock(); }
}

5Contention in Design Reviews and Shared Learning

The cheapest place to fix contention is before the code exists. I would add a short section to the design review template: what shared mutable state does this design keep on a hot path, how often is it read and written, which lock protects it, and what happens at ten times today's traffic? Reviewers who have seen contention incidents recognise risky shapes quickly: a synchronized cache with a remote reload, a global counter updated per request, a single queue that every request passes through.

Finally, incident write-ups are where those reviewers learn. When a contention incident happens, the review is shared beyond the team, in an engineering-wide forum or newsletter, with the stack, the lock and the fix. Over a year, recurring shapes become checklist items and sometimes static checks, for example flagging remote calls inside synchronized blocks.

Step throughHow a contention pattern becomes prevention
  1. Incident or profiler findinga hot lock in production
  2. Blameless write-up, shared widelystack, lock, fix, how to detect
  3. Seen in more than one team?
    YesAdd to the design review checklistNoKeep as a reference example
  4. Automate where possiblestatic check, load-test assertion, alert

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

6Rolling It Out Without Overloading Teams

Doing all of this for every service at once would stall. I would start with the ten services on the critical revenue path, provide the pieces centrally, JFR in the base image, a load-test template, standard saturation dashboards and alerts, so each team only has to adopt them, and measure the result: how many contention issues were found before release or by the profiler versus in incidents. When that share rises, for example from 10% to 70% over two quarters, the case for extending it to more services makes itself.

7Follow-up questions

How do you justify the cost of production-like load tests?

By comparing it with the cost of the incidents they prevent. One hour of checkout degradation at peak can cost more than a year of a pre-production environment. I would also share the environment and scripts across teams and run the heavy tests nightly and before releases rather than on every commit, which keeps the cost reasonable.

What if teams ignore the profiler's findings?

Findings need an owner and a place in normal planning. I would route them like other quality issues, as tickets to the owning team with severity based on projected impact, review the open ones in a regular operational review, and make sure leadership sees the trend. People act on findings when they are specific, cheap to understand and visibly tracked.

Is a lock wait metric in code worth the effort?

Only for locks we already know are on a hot path, because instrumenting every lock adds noise and overhead. For the general case, JFR and the profiler cover all locks without code changes. A dedicated metric makes sense for a known critical lock where we want an alert, not just a profile.

8Conclusion

In this answer, we saw that contention hides at low load and grows quickly with traffic, which is why it surfaces in incidents. To find it earlier we combined five practices: load tests at production concurrency that track lock wait totals, continuous JFR or profiling with lock views in production, saturation metrics and alerts for pools, executors and known hot locks, a contention question in design reviews, and widely shared incident write-ups that turn recurring shapes into checklist items, rolled out first on critical services and measured by how many issues are found before users notice.

What to say in the interviewAbout 90 seconds aloud

Open with

Contention shows up in incidents because it is invisible at low load and grows sharply once a lock is busy most of the time, and our normal tests never reach that concurrency.

Then, if they want more

So I would attack it from both ends. Before release, critical services get load tests that reach production-like concurrency with realistic data, run nightly and before releases, and they record p99 and lock wait totals from JFR so a release that doubles waiting on a lock gets flagged even if latency still passes.

In production, every JVM runs JFR continuously with lock events, and for critical services a continuous profiler with lock and wall-clock views lets us compare releases and catch a hotter lock before users notice.

I would make saturation a first-class metric: connection pool pending and acquire time, executor queue depth, and wait time for known hot locks, with alerts on trends rather than outages. In design reviews I would add a question about shared mutable state on hot paths and what happens at ten times the traffic.

And I would make sure contention incident reviews are shared across engineering so recurring patterns become checklist items or static checks. I would start with the ten most critical services, provide the tooling centrally so teams only adopt it, and measure what share of contention issues we now find before incidents.

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 "Contention problems in your organisation are usually found only during incidents. What...": https://scrivio-interview-library.netlify.app/java/concurrency-problems/43da21be0f/