Quick revision
The short answer
We make the answer already exist before the page arrives: continuous low-overhead profiling of every service, JFR-based or async-profiler-based, with flame graphs stored per service and version, plus an always-on JFR ring buffer that is dumped automatically when the alert fires. Dashboards split CPU into GC, JIT and application time and show throttling, a controlled debug image gives on-call jcmd and profilers when they need more, and a runbook with a comparison against the previous release's profile turns most cases into a ten-minute routine. Incident reviews keep improving the tooling.
What to remember
In this answer, we designed tooling that lets on-call engineers diagnose a typical high CPU case in about ten minutes. Continuous low-overhead profiling stores flame graphs per service and version, an always-on JFR ring buffer is dumped automatically when the alert fires, dashboards split CPU into GC, JIT and application time and show throttling, and a controlled debug image provides jcmd and profilers when needed. A runbook built around comparing the flame graph with the previous release turns diagnosis into a routine, and reviews after each incident keep improving the tools.
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.
We make the answer already exist before the page arrives: continuous low-overhead profiling of every service, JFR-based or async-profiler-based, with flame graphs stored per service and version, plus an always-on JFR ring buffer that is dumped automatically when the alert fires. Dashboards split CPU into GC, JIT and application time and show throttling, a controlled debug image gives on-call jcmd and profilers when they need more, and a runbook with a comparison against the previous release's profile turns most cases into a ten-minute routine. Incident reviews keep improving the tooling.
Why this question is asked
When on-call engineers take hours to explain a high CPU alert, the problem is rarely their skill. It is that every investigation starts from nothing: find the pod, get a shell, discover that the image has no jcmd, install a profiler, and by then the spike is over. Interviewers ask this design question to see whether we can turn diagnosis into a system: collect the right data before it is needed, present it so the cause is obvious, and make the remaining steps routine. In this answer, we will look at where the hours go today, design each part of the tooling, write the ten-minute runbook, and keep it improving.
1Where the Hours Go Today
If we look at a few past incidents, the time is usually spent on the same things. Getting access to the right pod and figuring out which of 30 replicas is affected takes 20 minutes. Finding that the container image is a minimal one with no diagnostic tools takes another 20. Taking a profile works only if the problem is still happening; often it is not. And then reading the flame graph without anything to compare it with makes it hard to say what is unusual.
So the design goal is clear. The data must already exist when the alert fires, it must be one click away from the alert, and there must be a baseline to compare it with. Most of a ten-minute diagnosis should be reading, not collecting.
2Continuous Profiling for Every Service
The foundation is continuous profiling: every JVM is sampled all the time at low frequency, for example 100 samples per second per process for CPU, and the stacks are sent to a central profiling backend that stores flame graphs labelled with service, version, pod and time. The collector can be based on async-profiler or on JFR's execution samples, and runs as an agent in the base image or as a node-level process, so teams do not have to set anything up.
The cost is small and predictable: typically around 1 percent CPU per service and a modest amount of storage, since aggregated stacks compress well. We set retention to, for example, 14 days of full detail and longer for daily aggregates. The benefit is decisive: when the alert fires, the flame graph of the last 15 minutes for exactly that service already exists, and so does the one from yesterday and from the previous release.
3Always-On JFR, Dumped on Alert
Continuous profiles answer where CPU goes. Sometimes we need more detail: GC pauses, safepoints, lock contention, thread activity and our own business events, all on one timeline. For that, every JVM runs a continuous JFR recording with a ring buffer, for example the last 2 hours, limited to 500 MB on disk.
When the high CPU alert fires, the alerting system calls a small agent that runs jcmd JFR.dump on the affected pods and uploads the files to a secure bucket, then adds the links to the alert. So even if the spike ends a minute later, the recording of the spike is preserved, and the on-call engineer receives the evidence together with the page.
6 messages in order. Play them, or step through them one at a time.
The engineer starts from evidence, not from an empty terminal.
4Dashboards That Split the CPU
The first question in any CPU case is whose CPU it is. So the standard JVM dashboard splits process CPU into GC, JIT compilation and application time, using JVM metrics for GC time and thread CPU by thread group where available. It also shows container CPU throttling, because a container hitting its CPU quota looks like a slow service, and the fix is completely different.
With this split, the first minute of the runbook answers the most important branch. High GC time sends us to memory: heap after GC, allocation rate, a possible leak. High JIT time just after a deployment is warmup and usually resolves itself. Throttling means the quota is too small or traffic grew. Only high application time sends us to the flame graph.
| Signal | Likely cause | Next step |
|---|---|---|
| GC share of CPU high, heap after GC high | memory pressure or leak | GC logs, histograms, memory runbook |
| JIT share high after a deploy | warmup | wait, check code cache if it persists |
| Throttling above 20% | CPU quota too small | raise limit or scale out |
| Application share high | hot code | flame graph diff against last release |
5A Debug Image With Access Controls
For the cases that need live interaction, such as several thread dumps or a lock profile, on-call needs tools in the running pod. Production images are often minimal, without a JDK's diagnostic tools, and that is a good security default. So we provide a separate debug image containing jcmd, async-profiler and a few Linux tools, and a supported way to attach it to a running pod, for example as an ephemeral debug container that shares the process namespace.
Access is controlled: only on-call engineers can start a debug container, the action is logged with who and why, and it is time-limited. This keeps the tools available in seconds without leaving them installed everywhere, and keeps a record of who touched production.
6The Ten-Minute Runbook
With the data and tools in place, the runbook becomes a short, repeatable routine. In the first two minutes, we open the dashboard linked from the alert and look at the CPU split and throttling. In the next three, if application CPU is high, we open the flame graph for the alert window and compare it with the same service on the previous release, or the same hour yesterday; the profiling backend's diff view highlights functions whose share grew. A new wide frame under a method changed in the last release usually is the answer.
If the diff is not conclusive, we open the JFR dump attached to the alert and look at hot methods, lock contention and GC. Only if all of that is unclear do we attach the debug image for live thread dumps or a lock profile. The runbook also says when to mitigate first, for example roll back if the CPU rose right after a release and latency is affected, so diagnosis does not delay recovery.
- Open dashboard from the alertminutes 0 to 2
- Is it GC, JIT or throttling?YesFollow that runbook branchNoApplication CPU: continue
- Flame graph diff vs last releaseminutes 2 to 5
- A new wide frame?YesFound: fix or roll backNoOpen the JFR dump from the alert
- Debug image, live dumps or lock profileonly if still unclear
5 steps in order. Play them, or step through them one at a time.
7Improving the Tooling After Each Incident
The design is not finished at launch. After each CPU incident, the review asks how long diagnosis took and what slowed it down. If an engineer needed a tool that was missing, a metric that was not on the dashboard or a profile that was not retained long enough, we add it. We also track the median time from page to identified cause, and aim to bring it from hours to about ten minutes, which makes the investment visible to management.
8Follow-up questions
How do you keep continuous profiling cheap at the scale of hundreds of services?
We sample at a low rate, aggregate stacks on the node before sending them, store aggregated profiles rather than raw samples, and set retention by value: full detail for two weeks, coarser aggregates for longer. We also measure the overhead on representative services and publish it.
What if the CPU spike lasts only a minute?
That is exactly the case the design is for. Continuous profiles already cover that minute, and the JFR ring buffer holds it for hours, so the evidence survives even though nobody was watching. Without these, short spikes are almost impossible to explain.
9Conclusion
In this answer, we designed tooling that lets on-call engineers diagnose a typical high CPU case in about ten minutes. Continuous low-overhead profiling stores flame graphs per service and version, an always-on JFR ring buffer is dumped automatically when the alert fires, dashboards split CPU into GC, JIT and application time and show throttling, and a controlled debug image provides jcmd and profilers when needed. A runbook built around comparing the flame graph with the previous release turns diagnosis into a routine, and reviews after each incident keep improving the tools.
Open with
The reason it takes hours today is that every investigation starts from nothing: find the pod, discover there are no tools in the image, try to profile after the spike is over, and then read a flame graph with nothing to compare it to.
Then, if they want more
So I would make the evidence exist before the page arrives. First, continuous profiling for every service, JFR or async-profiler based, at a low sampling rate, with flame graphs stored per service, version and pod for a couple of weeks, at about 1 percent overhead.
Second, an always-on JFR ring buffer in every JVM, and when the CPU alert fires, an agent dumps it and attaches the link to the page.
Third, a standard dashboard that splits CPU into GC, JIT and application and shows throttling, because the first branch is whose CPU it is: GC means memory, JIT after a deploy means warmup, throttling means quota. Fourth, a debug image with jcmd and async-profiler that on-call can attach as an ephemeral container, with access logged.
Then the runbook is short: two minutes on the dashboard, three minutes on a flame graph diff against the previous release, then the JFR dump, and live debugging only if still unclear. After each incident we review what slowed us down and track time to cause.
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 "On-call engineers are paged for high CPU on different JVM services every week and take...": https://scrivio-interview-library.netlify.app/java/jvm-diagnostics/efe3049d1b/