Java Developer Interview Question

Your 99th percentile latency has spikes that the application code cannot explain. How do you check whether garbage collection is responsible?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Turn on garbage collection logging and line the pause timestamps up against the slow requests. If the spikes match pauses, look at allocation rate, promotion and heap headroom before touching any flags, since most pauses come from allocating too much or a heap that is too small. If they do not match, check time to safepoint, since a long safepoint stalls every thread and looks exactly like a garbage collection pause.

Why interviewers ask this

Tail latency debugging is a senior skill, and the interviewer wants evidence rather than guessing at flags. Correlating pause logs with request traces, and knowing that safepoints, page faults or a noisy container neighbor can produce the same symptom, shows methodical thinking. It also reveals whether you would fix the cause in the application or paper over it with collector tuning.

How to structure your answer

  • Get the data: garbage collection logs plus per request timings.
  • Correlate pause windows with the slow requests.
  • Investigate allocation rate and heap sizing before flags.
  • Consider non garbage collection causes such as safepoints or the platform.

Example answer

Spoken example, first person

I want two timelines. Unified logging gives me every pause with its cause and duration, and my traces give me the slow requests, so the first question is simply whether they line up. If they do, I resist changing flags and look at why. Usually the service allocates enormously per request, something like building intermediate lists in a loop or logging a serialized payload on every call, so the fix is allocating less. Sometimes the heap is just too tight and collections run constantly, or in G1 the code allocates large arrays that become humongous objects and behave badly. Only after that would I consider moving to a low pause collector, and I would treat it as a tradeoff rather than a free win. If the pauses do not correlate, I look elsewhere: time to safepoint can be long even when the collection itself is short, so a thread in a counted loop stalls everyone. I have also chased a case that turned out to be container CPU throttling, where the process was descheduled entirely and no JVM tuning would have helped.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • What is a safepoint, and why can reaching one take a long time?
  • How would you reduce allocation rate in a hot request path?
  • How does container CPU throttling show up in JVM metrics?

Related java developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot