Performance Troubleshooting & Incident Response Questions
Diagnosing and resolving performance problems in production, often under time pressure. Covers latency and slowdown investigation, reproducing and narrowing performance regressions, reading live diagnostic evidence (logs, thread dumps, resource and network captures), runbooks and automated remediation for recurring incidents, restoring healthy behavior while preserving reliability, and communicating status and escalation decisions mid-incident. Emphasizes systematic debugging of live systems over offline experimentation.
Explain how you would determine whether a latency regression is caused by increased contention (locks) versus increased garbage collection in a JVM service. Which metrics and tooling would you use and what patterns would confirm each hypothesis?
Sample Answer
Separate the two hypotheses by where the time is actually going: elevated GC (garbage collection, the JVM's automatic memory reclamation) shows up as measurable pause time and real CPU spent inside GC threads, while lock contention shows up as threads sitting BLOCKED waiting on a monitor (here, a monitor is the built-in lock object a thread must acquire to enter a synchronized block, not a monitoring or APM tool), with normal GC activity and often normal or even low CPU usage, since blocked threads aren't computing at all.
Metrics and tooling for the GC hypothesis
- GC logs (enabled with a flag like
-Xlog:gc*) showing pause frequency, pause duration, and what percentage of wall-clock time the process spends paused. jstat -gcutilfor live young/old generation occupancy and GC count and time.- A heap-usage graph with a sawtooth pattern climbing close to max before every collection, and collections becoming more frequent and longer, points to memory pressure driving GC.
- A flame graph (a visualization where the width of each bar shows how much time was spent in that function, making hot code paths easy to spot) or APM (application performance monitoring) tool showing GC threads consuming a meaningful share of total CPU.
Metrics and tooling for the lock-contention hypothesis
- Thread dumps (as described for reading BLOCKED-thread patterns) showing many threads funneling to one lock holder.
jstackor a JFR (Java Flight Recorder) contention profile giving monitor wait time per lock directly.- Latency degrading WITHOUT a corresponding rise in CPU usage or GC time is the key signature, CPU can even look under-utilized because threads are idle waiting rather than computing.
Confirming which one applies
- GC: pause times line up directly with the timing of the latency spikes (a spike coincides with a stop-the-world pause), and reducing allocation rate or retuning the GC algorithm reduces pause time and latency together.
- Lock contention: the regression tracks with rising concurrency (more threads means more competition for the same lock) rather than with memory pressure, and repeated thread dumps taken during the slow window show the same BLOCKED pattern every time.
Worked example: p99 latency (99th percentile: the value below which 99% of requests fall) degrades from 80ms to 400ms under peak traffic. GC logs show average pause time unchanged at 15ms and pause frequency unchanged from the healthy baseline, ruling out GC as the driver. Three thread dumps taken 5 seconds apart during the slow window all show more than 30 threads BLOCKED on the same synchronized cache-refresh method, confirming lock contention: the cache lookup logic was holding a lock for the entire refresh instead of only while swapping the reference.
Trade-offs and pitfalls: the two causes can co-occur, heavy contention can force more object retention which then increases GC pressure, so treat the first hypothesis that fits the evidence as a starting point, not a final answer, and re-check after any fix lands. A common mistake is reading normal CPU utilization as proof it "must be locks" without checking a GC log, since a moderately sized heap can still produce infrequent but very long pauses that a coarse CPU average won't reveal.
A distributed service shows sporadic 5-10 second latency spikes. Metrics show brief CPU usage increases and GC pause time increases at the same times, but also an uptick in external API retries. Propose a root cause analysis plan that accounts for these mixed signals and outline how you'd isolate the true cause.
Sample Answer
Direct answer: With three signals moving together (CPU, GC pause time, and external API retries), the trap is treating them as three independent causes when they may really be A causing B causing C, or all three being downstream symptoms of a fourth thing, like a traffic burst. The plan has to establish which one moved first and then test the causal story directly, not just observe that they correlate.
Structured elaboration:
- Reconstruct a fine-grained timeline. Pull second-level, not minute-level, time series for CPU, GC pause events, and retry counts around a single spike, overlaid on the same axis. Whichever metric's rise leads the others, even by a few hundred milliseconds, is the more likely upstream cause, though leading correlation alone is still not proof.
- Check for a shared upstream cause. Look at request concurrency or queue depth in the same window. If it spikes before all three of the other metrics, none of CPU, GC, or retries is the root cause; they're co-symptoms of a traffic burst instead.
- Test each hypothesis independently, don't just rank them by correlation:
- To test "a GC pause froze the app long enough to trip the external call's timeout," check whether retry timestamps cluster right after logged GC pause events, and whether the configured call timeout is short enough that a pause of that duration alone would trip it.
- To test "the external API got slow first, which caused retries, which caused GC/CPU pressure," check the external API's own latency or status data during the spike window; if it was degraded before your CPU or GC metrics moved, that argues it's upstream.
- To test "a third confounder like a traffic burst," check whether the spikes line up with a known pattern (a batch job, a caller's own retry storm, a marketing push) independent of CPU, GC, and the external API.
- Reproduce the leading hypothesis in isolation. If you suspect the external API, fault-inject several seconds of added latency into a shadow call to that same dependency in staging at similar concurrency, and see if you reproduce a comparable GC-pause and CPU signature. Reproducing the coupled symptom by injecting only one variable is strong confirmation.
Worked example: In one eight-second spike, retry timestamps for the external API start climbing about 1.5 seconds before GC pause time increases, and about 2 seconds before CPU jumps. Checking the external API's own status dashboard shows a brief documented degradation in that exact window. That ordering plus outside corroboration point to: the external API slowed down, your client retried aggressively, the resulting retry storm (more concurrent in-flight requests and objects) drove up allocation rate, and GC pressure and CPU followed as downstream effects. You confirm by fault-injecting three to four seconds of added latency on a shadow call to that dependency in staging at comparable concurrency and reproduce a similar GC-pause and CPU bump.
Trade-offs and pitfalls: leading-edge correlation in a single incident is suggestive, not conclusive; you want the same ordering to hold across multiple spikes before committing engineering effort to a fix. It's also easy to over-index on whichever metric is loudest (CPU usually pages first) instead of tracing it backward, and it's a mistake to assume all three symptoms must share one root cause; the isolation step protects against wrongly merging two coincidental problems into a single story. Once the retry storm is confirmed as the trigger, the fix is adding jittered exponential backoff and a retry budget (a cap on how much total traffic is allowed to be retries) or a circuit breaker (a safeguard that stops sending requests to a dependency once its failure rate crosses a threshold, so it gets a chance to recover instead of being retried into the ground) on that external call, so a downstream blip can't amplify into a retry storm again.
After a deploy, your service's p95 latency jumps 40% and holds there. Walk through how you would investigate: what telemetry and traces you would check first, what experiments you would run (including load tests and fault injection) to narrow the cause down to CPU, GC, network, or a downstream dependency, and how you would decide between rolling back the deploy and shipping a targeted fix.
Sample Answer
Direct answer: When p95 latency (the 95th percentile response time) jumps and then holds flat right after a deploy, the fastest lever is usually rollback, since it's reversible in minutes, while you diagnose in parallel. Don't let the search for root cause block the mitigation decision.
Structured elaboration:
- Telemetry first: compare the new deploy's dashboards against the prior version for CPU utilization, garbage collection (GC: a managed runtime periodically pausing to reclaim memory it no longer needs) pause frequency and duration, downstream dependency latency from traces, and network-level retry or error counts, ideally split by version if canary tagging exists.
- Trace comparison: pull a handful of the slowest request traces from before and after the deploy and look at the span waterfall. Is the extra time inside your own service's code, in a lock, or waiting on a downstream call?
- Experiments: fault-inject added latency into one candidate downstream dependency in staging and measure how many milliseconds of p95 you get per millisecond you inject. Be precise about what that buys you, because it is easy to overclaim: reproducing a p95 shift proves only that the call sits on the request's critical path and gives you a sensitivity coefficient. It does not show that this dependency is what changed in production, which is the actual hypothesis. The causal argument needs both halves multiplied together: the sensitivity from the injection, and the dependency's own measured latency delta in production across the deploy boundary, with the product accounting for most of the observed p95 move. If the dependency's latency did not move in production, a clean injection result is irrelevant no matter how well it reproduces, and if it did move but only by 5ms against a 120ms p95 jump, it is a contributor and not the cause. Separately, load-test the new version alone, without any real downstream dependencies in the loop, at matching request volume, to see if the code path itself (CPU or GC) explains the jump on its own.
- Categorize the eventual fix along four axes: code (an inefficient new code path, such as added serialization or computation), resources (an undersized CPU, memory, or thread-pool allocation for the new code path), network (a chattier call pattern with more round trips), or configuration (a changed timeout, connection-pool size, or feature-flag default).
- Rollback versus fix forward: default to rollback in the first response window since it's low-risk and reversible. Fix forward only when the regression traces to a single config value you can flip immediately (a feature flag), or when rollback itself carries real risk, for example if the deploy also included a data migration that isn't safely reversible.
Worked example: The deploy goes out at 10:00. p95 jumps from 300ms to 420ms (a 40% increase) immediately afterward and holds flat for the next hour rather than climbing further, which rules out a slow leak and points to a discrete step change caused by the deploy itself. Trace comparison shows CPU time spent inside your own process rose from about 40ms to about 150ms per request, with no material change in downstream call latency, and GC pause telemetry is unchanged. That combination points to code, not GC and not network. You fault-inject 100ms of extra latency into that downstream dependency in staging and staging's p95 moves by roughly the same 100ms, which establishes sensitivity of about 1ms of p95 per 1ms of dependency latency and nothing more. The production traces show that dependency's own latency unchanged across the deploy boundary, so there is no delta for that sensitivity to act on: 1.0 times roughly zero explains none of the 120ms. "The dependency coincidentally got slower" is ruled out by the production measurement, not by the injection, and the injection's real value here was proving the traces were not simply missing the call. With no config change involved and the regression clearly inside application code, you roll back rather than trying to patch the code path live under pressure.
Trade-offs and pitfalls: rollback isn't free either. If the deploy included a schema or data change, rolling back the code without also reversing the data change can leave the system in an inconsistent state, so check reversibility before defaulting to it. Chasing GC or network hypotheses before ruling them out with the telemetry you already have wastes time exactly when time is scarce, and trusting a single slow-trace sample without a second one to confirm the pattern risks over-fitting to noise.
A search service is showing high tail latency under load. Walk through how you would figure out what's actually causing it and what you would change to bring it back down, and how you would prove your fix actually worked.
Sample Answer
When tail latency is high specifically under load, the goal is to find which resource is actually saturating (saturation meaning work is queuing up waiting to be served, not just busy) before touching any code, and then to validate the fix at the same load level that broke it.
Diagnose
- Compare p50 (median) against p99 (99th percentile) latency as load increases. If p50 stays flat while p99 balloons only past a certain QPS (queries per second), that's a saturation or queueing signature, not a uniform slowdown affecting every request equally.
- Apply the USE method systematically per resource: check Utilization (how busy), Saturation (how much work is queued beyond capacity), and Errors for each candidate resource, CPU, thread pool, connection pool (a shared, size-limited set of pre-opened connections to a downstream system that requests borrow and return instead of opening a new one each time), downstream call, disk IO, so you're sweeping possibilities instead of guessing.
- Check whether the slow requests share a shape: large result sets, cold cache lookups, or cross-shard fan-out calls (where one request touches many backend shards and waits on all of them) are common tail-latency culprits that don't show up in average-case metrics.
- Trace the slowest 1% of requests directly rather than reading aggregate dashboards, since an average hides which single stage of the request pipeline is actually slow.
Fix
- Mitigate immediately if customers are affected: shed excess load, add timeouts and circuit breakers (safeguards that stop sending requests to a struggling dependency once its failure rate crosses a threshold, giving it a chance to recover) to cap the worst case, or scale out horizontally if the bottleneck is genuinely per-node capacity.
- Fix the root cause once found: commonly this is an undersized thread or connection pool causing queueing past a load threshold, one slow shard dragging down every fan-out request that touches it, GC (garbage collection) pauses under memory pressure, or a lock serializing a hot path.
Proving the fix worked
- Reproduce the same load pattern (not just lighter production traffic) that originally triggered the regression, ideally in a load test, before and after the change.
- Confirm p99 (and ideally p99.9) returns to baseline at that SAME load level, since tail problems can hide entirely at low load and reappear the moment traffic climbs again.
- Watch it survive a full production traffic cycle including peak, and add an alert on the specific percentile that regressed so a recurrence pages automatically instead of waiting for another complaint.
Worked example: p50 stays flat at 40ms from 100 QPS up to about 1500 QPS while p99 rises from 90ms to 900ms across that same range; past roughly 1650 QPS p50 starts climbing too and the load test stops reaching a steady state at all. Tracing the slowest requests shows they all wait on a connection pool to a downstream ranking service capped at 50 connections. Size that pool analytically instead of reading a number off the graph. With a 30ms average call time each connection completes 1 / 0.030 = 33.3 calls per second, so 50 connections have a hard throughput ceiling of 50 / 0.030 = about 1670 QPS, while the concurrency actually demanded is Little's law: 1500 x 0.030 = 45 connections at 1500 QPS, and 60 at 2000 QPS. That one ceiling explains both breakpoints and why they are different breakpoints. At 1500 QPS the pool is at 45 of 50, about 90% utilized, which is far enough up the queueing curve to wreck p99 while the median request still finds a free connection immediately, and that is exactly the divergence between median and tail the diagnosis started from. At 2000 QPS demand exceeds the 1670 QPS ceiling outright, so the wait queue grows without bound, every request waits including the median, and no percentile is stable, which is why a tail-only story stops being the right description above the ceiling. Raising the pool to 150 lifts the ceiling to about 5000 QPS, putting 2000 QPS at 40% utilization with real room for the tail, and adding a 200ms client timeout with one retry to a second replica brings p99 back under 120ms at 2000 QPS in a repeat load test.
Trade-offs: raising a pool size blindly can just relocate the bottleneck downstream, if the ranking service itself is near its own capacity, sending it more concurrent connections saturates it instead. Hedged requests (sending a duplicate request to a second replica when the first is slow) fix tail latency but add real load to the downstream system, so cap how often they fire.
You have the following log snippet from a backend service:
[2025-06-01T12:34:10Z] WARN request_id=abc123 duration_ms=1200 upstream=database timeout_ms=1000
[2025-06-01T12:34:11Z] WARN request_id=def456 duration_ms=1400 upstream=cache timeout_ms=500
What immediate conclusions can you draw about the type of performance problem, and what next steps would you take to validate and prioritize fixes?
Sample Answer
Direct answer: Both requests exceeded their own timeout, but not by the same margin: the database call ran 20% over its timeout, while the cache call ran 180% over its. Since a cache lookup is normally fast, that disproportionate breach makes the cache call the more anomalous of the two, and the fact that both upstreams (the dependencies this service calls out to, here the database and the cache) breached their timeouts about a second apart is more consistent with a shared cause than two unrelated slow dependencies.
Structured elaboration:
- Do the arithmetic on how far over timeout each call actually ran. Database: 1200ms actual duration against a 1000ms timeout, a ratio of 1200/1000 = 1.2, so 20% over. Cache: 1400ms actual duration against a 500ms timeout, a ratio of 1400/500 = 2.8, so 180% over. The cache breach is proportionally far worse even though its raw duration (1400ms) is only slightly higher than the database's (1200ms).
- Ask why each duration exceeds its own timeout at all. This is the sharpest clue in the two lines and it is easy to walk past. A call configured with a 500ms timeout should have been abandoned at about 500ms, so a logged duration of 1400ms demands an explanation, and there are only three candidates:
duration_mscovers a whole attempt sequence rather than one attempt (1400ms is close to three 500ms attempts back to back), the timeout is not enforced on the leg that matters (the classic version is a connect timeout configured with no read or total-call timeout, so a socket that connects fast and then stalls runs unbounded), orduration_msis end-to-end request time and the upstream call is only one part of it. The database line discriminates between those readings: 1200ms against a 1000ms timeout is one attempt plus about 200ms of surrounding work, which is exactly what a correctly enforced single-attempt timeout looks like. The most economical story that fits both lines is therefore one attempt against the database and about three against the cache, and that materially changes the plan: a client retrying three times into a struggling cache is adding load to the thing that is already slow, so capping retries there is a mitigation available immediately, before anyone has found the root cause. - Read WARN as "slow," not automatically "failed." Check whether these requests were retried and eventually succeeded, or resulted in a hard error, before assuming customer impact. That check and the one above are the same check: the retry count is what tells you whether 1400ms was one long stall or several bounded ones.
- Check volume before drawing conclusions. Two WARN lines could be background noise if they're two out of thousands of requests, or evidence of a systemic issue if they're a large fraction of traffic in the same window. Aggregate WARN counts by upstream over the last 15 to 30 minutes.
- Check whether it's the same host or different hosts. Both log lines coming from the same host points toward a host-level resource issue (network interface saturation, meaning the network card is at its maximum data-transfer capacity, or a noisy neighbor: another workload sharing that same host competing for the same CPU, memory, network, or disk capacity and starving yours); different hosts hitting both a database and a cache in the same window points toward a shared network path or shared infrastructure problem.
- Prioritize the cache investigation first, because its timeout breach is proportionally larger, because the retry reading above makes it the one call actively adding load to its own dependency, and because cache failures often cascade: if the cache is unhealthy, more requests fall through to the database, which would explain both WARN lines from a single root cause rather than two independent ones.
Trade-offs and pitfalls: it's easy to fixate on the larger raw duration number (1400ms) without computing the ratio against each call's own timeout, which is what actually tells you which one is more abnormal. It's also a mistake to treat two WARN log lines as proof of a systemic problem before checking whether they represent 0.1% or 50% of traffic in that window.
Unlock Full Question Bank
Get access to all 23 Performance Troubleshooting & Incident Response interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.