Quick revision
The short answer
The core principle is to diagnose from data recorded before the incident rather than to reproduce it afterwards, so every JVM records continuously with built-in, low-overhead sources such as JFR and unified logging, in open formats. That data must be correlated with traces and logs through shared identifiers, collected within an explicit budget for cost and retention, treated as sensitive, and backed by trained engineers and a diagnosability requirement that every service must meet.
What to remember
In this answer, we turned fifteen years of JVM tooling changes into six principles: record before the incident instead of reproducing it after, prefer built-in, low-overhead sources and open formats, correlate JVM data with traces and logs through shared identifiers, budget the cost of collection and retention, treat diagnostic data as sensitive, and make diagnosability a requirement backed by training. Each principle is there because tools change, while the need for cheap, readable data from before the incident does not.
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.
The core principle is to diagnose from data recorded before the incident rather than to reproduce it afterwards, so every JVM records continuously with built-in, low-overhead sources such as JFR and unified logging, in open formats. That data must be correlated with traces and logs through shared identifiers, collected within an explicit budget for cost and retention, treated as sensitive, and backed by trained engineers and a diagnosability requirement that every service must meet.
Why this question is asked
Fifteen years ago, diagnosing a JVM meant running jstat in a terminal, reading verbose GC output and hoping to catch the problem while it was happening. Today the JVM itself records events continuously with JFR, logs in a single unified format, and continuous profilers show where every service spends its CPU. The tools will keep changing, so a senior engineer setting direction for a large fleet cannot simply pick a tool. Interviewers ask this question to see whether we can turn experience into a few durable principles that survive tool changes, explain the reasoning behind each, and make them stick across hundreds of teams. In this answer, we will look at what the last fifteen years taught us, then go through six principles, what each costs, and how to turn them into requirements and habits.
1What Fifteen Years of Tool Changes Teach Us
The older tools had one thing in common: they were mostly used after someone noticed a problem. jstat printed GC statistics while we watched. Verbose GC flags wrote logs in formats that changed between collectors and versions. Profilers were attached by hand and often changed the behaviour they measured. So the typical investigation started with trying to make the problem happen again, which for intermittent production issues often failed.
Three shifts changed this. Unified logging, introduced in JDK 9 with -Xlog, gave GC, safepoints and class loading one consistent, configurable format. JFR, open-sourced in JDK 11, made it cheap enough to record JVM events all the time. And continuous profiling, sampling stacks across the whole fleet and storing flame graphs, made it possible to compare today's CPU use with last week's. The lesson is that the valuable property was never a particular tool; it was having low-cost data from before the problem, in a form we could still read later.
| Era | Typical source | Main limitation |
|---|---|---|
| Early | jstat, verbose GC flags, manual thread dumps | only useful while watching; formats varied |
| JDK 9 onwards | unified logging with -Xlog | logs only, no stacks or events |
| JDK 11 onwards | JFR open-sourced, always-on recordings | needs storage and tooling to use well |
| Recent years | continuous profiling across the fleet | cost, retention and data volume to manage |
2Principle 1: Record Before the Incident, Do Not Reproduce After
The first principle sets the direction for everything else. Every service records enough, all the time, that a typical incident can be explained from data captured while it happened. In practice that means a continuous JFR recording with a ring buffer, GC and safepoint logging with rotation, a heap dump on OutOfMemoryError written to a persistent location, and continuous CPU profiles.
The reasoning is economic. An engineer spending a day trying to reproduce a rare latency spike costs far more than the storage for a few hours of JFR data on every pod. And some problems, such as one bad node or one strange traffic pattern, cannot be reproduced at all. A useful test for this principle is to ask, after each incident, whether the data we needed was already there. If the answer is often no, the principle is not yet real.
3Principle 2: Prefer Built-In Sources and Open Formats
For the next decade, we prefer data sources that ship with the JDK, such as JFR and unified logging, and open formats, such as JFR files and OpenTelemetry signals, over proprietary agents that rewrite bytecode. Built-in sources are maintained by the JVM's own developers, tested with each release and designed to have low overhead. Open formats mean we can change our storage or analysis vendor later without losing years of history or rewriting instrumentation.
This is a preference, not a ban. A commercial product may give a much better analysis experience, and that is fine as long as it can read the standard data. What we avoid is a situation where switching vendors means re-instrumenting a thousand services.
4Principle 3: Correlate Everything Through Shared Identifiers
JVM data on its own answers JVM questions. A GC pause at 14:03 matters only when we can connect it to the slow checkout requests at 14:03. So every source must carry identifiers that join them: service name, version, pod or host, and for request-level data the trace id that also appears in logs and distributed traces. Custom JFR events can carry the trace id, and profiles can be labelled with service and version.
The reasoning is that most time in an investigation is spent switching between tools and lining up timestamps by hand. Shared identifiers turn that into a query. We set the naming of these identifiers once, for the whole fleet, because every team inventing its own label names defeats the purpose.
5Principle 4: Budget the Cost and Decide What to Keep
Recording everything forever is not affordable. A fleet of 3,000 JVMs producing 200 MB of JFR data per hour each would generate about 14 TB per day. So we budget explicitly: an overhead target per service, for example under 2 percent CPU, and a retention plan. A common shape is to keep raw recordings locally for hours, dump and store them centrally only on alerts or incidents, keep aggregated profiles for weeks, and keep derived metrics for months.
This principle protects the others. Without a budget, observability costs grow until someone cuts them in a hurry, usually removing exactly the data the next incident needs.
6Principle 5: Treat Diagnostic Data as Sensitive
Heap dumps contain everything in memory, including customer data, tokens and passwords. JFR recordings contain command lines, system properties, environment variables and string fields. So diagnostic data gets the same treatment as production data: encrypted storage, short retention for raw dumps, access limited to people who need it, and an audit log of who downloaded what. We also make attaching tools to production a controlled action, so that a profiler or jcmd session is logged and authorised rather than something anyone with a shell can do.
The reasoning is that the diagnostic path is easy to forget in a security review, and a leaked heap dump can be as damaging as a leaked database backup.
7Principle 6: Make Diagnosability a Requirement and Train People
Principles only matter if they reach every service. So we make diagnosability part of the production readiness checklist: a service is not ready until it runs the standard runtime profile, its recordings can be dumped and opened, and its dashboards show heap after GC, GC time and CPU split by GC, JIT and application. The platform team provides this in the base image so meeting the requirement costs a team almost nothing.
Tools alone do not help if only three experts can read a flame graph. We write runbooks for the common cases, run practice sessions where on-call engineers diagnose a recorded incident, and review incidents for what the tools could not answer. Over a decade, the people and the habits outlast every tool we choose today.
- Incident resolved
- Was the data already recorded?YesNote what helpedNoAdd the missing source to the standard profile
- Could the on-call engineer read it?YesKeep the runbookNoImprove runbook and training
- Review cost and retention once a quarter
4 steps in order. Play them, or step through them one at a time.
8Follow-up questions
How do you convince teams to accept even 1 or 2 percent overhead?
By showing measured numbers rather than promises, and by comparing them with the cost of incidents. We run load tests on representative services, publish the overhead, and point to incidents that the data explained in minutes. We also make it easy to opt out temporarily, which builds trust that the platform team will not ignore a real problem.
What would you do about services that run on older JDKs without these features?
We treat the JDK upgrade as part of the diagnosability plan. In the meantime we apply what the old version supports, such as GC logging and heap dumps on OutOfMemoryError, and we record the gap explicitly so it gets prioritised rather than forgotten.
Is continuous profiling worth it when you already have JFR?
Often yes, because the value is in aggregation: comparing CPU profiles across versions and across the fleet. JFR gives deep data for one JVM over a window; a profiling backend answers questions such as which release made this service use 20 percent more CPU. Many continuous profilers can use JFR as their data source, so the two work together.
9Conclusion
In this answer, we turned fifteen years of JVM tooling changes into six principles: record before the incident instead of reproducing it after, prefer built-in, low-overhead sources and open formats, correlate JVM data with traces and logs through shared identifiers, budget the cost of collection and retention, treat diagnostic data as sensitive, and make diagnosability a requirement backed by training. Each principle is there because tools change, while the need for cheap, readable data from before the incident does not.
Open with
My main principle is that we diagnose from data recorded before the incident instead of trying to reproduce it later, because reproduction is slow and for intermittent production problems often impossible.
Then, if they want more
So every JVM runs a standard profile: a continuous JFR ring buffer, rotated unified GC and safepoint logs, heap dumps on OutOfMemoryError to a persistent path, and continuous CPU profiling. Second, I prefer built-in, low-overhead sources like JFR and unified logging and open formats like JFR files and OpenTelemetry, so we can change vendors without re-instrumenting the fleet.
Third, everything carries shared identifiers, service, version, pod and trace id, so a GC pause can be joined to the slow requests it caused. Fourth, there is an explicit budget: an overhead target per service and a retention plan, raw data locally for hours, dumps on alert, aggregates for weeks.
Fifth, diagnostic data is sensitive, so encrypted storage, short retention and audited access. And sixth, diagnosability is part of production readiness, provided by the platform in the base image, with runbooks and practice sessions so it does not depend on a few experts. After each incident I ask whether the data was already there, and fix the gaps.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 11, Java 9
- 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 "JVM observability moved over 15 years from jstat and verbose GC flags to unified...": https://scrivio-interview-library.netlify.app/java/jvm-diagnostics/6d9d7b39a1/