Quick revision
The short answer
We start by defining the goal precisely (which latency metric, under what load, against what target), reproduce the miss with realistic load and data, and record a baseline. Then we find where the time actually goes before touching anything, using GC logs, JFR, wall-clock and CPU profiles, and traces of downstream calls. If GC turns out to be the cause, we decide between reducing allocation or live data in the code and adjusting the collector or heap. We change one thing at a time, measure and record each experiment, and validate the winning change in a canary with production traffic before rolling it out.
What to remember
In this answer, we followed a tuning method for a missed p99 SLO: define the metric, load and target; reproduce on a production-shaped pod and record a baseline; find where the time goes with traces, JFR and profiles before changing anything; treat GC with allocation and live data fixes in code or heap and collector changes in the JVM; change one thing at a time with a written experiment log; and validate in a canary with production traffic before rollout.
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 start by defining the goal precisely (which latency metric, under what load, against what target), reproduce the miss with realistic load and data, and record a baseline. Then we find where the time actually goes before touching anything, using GC logs, JFR, wall-clock and CPU profiles, and traces of downstream calls. If GC turns out to be the cause, we decide between reducing allocation or live data in the code and adjusting the collector or heap. We change one thing at a time, measure and record each experiment, and validate the winning change in a canary with production traffic before rolling it out.
Background to this question
A missed p99 SLO, meaning the slowest one percent of requests is slower than promised, is one of the most common performance problems in Java services, and one of the easiest to make worse. The instinct is to change GC flags first, because GC is the famous source of Java latency. Often the real cause is a slow downstream call, lock contention or a burst of allocation, and flag changes only add noise. This question tests whether we follow a method. In this answer, we will define the goal, reproduce and baseline, find where the time goes, deal with GC when it is the cause, run disciplined experiments, and validate in production.
1Define the Goal Precisely
A vague goal like make it faster cannot be tested. We write down the metric, the conditions and the target. For example: p99 latency of POST /orders, measured at the service's HTTP server, at 1,200 requests per second with the production mix of order sizes, must be under 250 ms; today it is 620 ms during the daily peak. We also note which latency we mean. A client-side p99 includes network and load balancer time, while a server-side p99 does not, and confusing the two sends us looking in the wrong place.
This step also tells us when we are done. Without a target, tuning never ends.
2Reproduce and Record a Baseline
Next we reproduce the miss outside production, with a load generator that sends the realistic mix at the realistic rate, against a pod shaped like production (same CPU and memory limits, same JDK and flags) and with production-like data volumes. A small test database or a 1 CPU staging pod can hide the problem or create a different one.
When the test reproduces the p99, we record the baseline: the latency distribution, throughput, CPU use, GC logs and the exact versions and flags. Every later experiment is compared against this baseline, and the load tool should report percentiles correctly, without hiding stalls (coordinated omission, where a stalled load generator stops sending and so never records the slow requests).
3Find Where the Time Goes Before Changing Anything
Now we look for the cause, and we look broadly. A distributed trace of the slow requests shows whether the time is spent inside our service or waiting for a database, cache or another service. A JFR recording shows GC pauses, lock contention (Java monitor blocked events), thread parks, socket reads and method samples. A CPU profile shows where we burn CPU, and a wall-clock profile shows where threads wait, which matters because latency is often waiting, not computing.
- Define metric, load and target
- Reproduce on a production-shaped podrecord a baseline
- Trace, JFR, CPU and wall-clock profileswhere does the time go?
- Is GC the main cause?YesReduce allocation or live data, or tune heap and collectorNoFix the real cause: calls, locks, queries
- One change, measure, record
- Target met in test?YesCanary with production trafficNoNext hypothesis
- Roll out and keep the record
7 steps in order. Play them, or step through them one at a time.
In this example, GC pauses are at most 38 ms, too short to explain a 620 ms p99, while a lock in PriceCache.get blocks threads for nearly two seconds in total. So the next step is the lock, not the collector. That is the point of this stage: we let the data choose the suspect.
4When GC Is the Cause
If the GC log shows long pauses that line up with the slow requests, we ask why. A high allocation rate means frequent young collections. A large live data set close to the heap size means frequent mixed or full collections. Evacuation failures or to-space exhausted messages in G1 mean the heap is too tight. There are two families of fixes.
The first is in the code: allocate less (avoid building large temporary collections, reuse buffers, stream instead of loading whole result sets), or keep less live data (smaller caches, bounded queues). These fixes reduce the work for every collector and survive JDK upgrades. The second is in the JVM: a larger heap gives the collector more room, a different pause target changes G1's choices, and for very low latency targets with large heaps, ZGC keeps pauses well under a millisecond at the cost of some throughput and memory. We usually try the code options first if the allocation profile shows a clear hot spot, and the heap or collector options when the allocation is inherent to the work.
5Change One Thing at a Time and Keep a Record
Each experiment changes exactly one thing, runs the same load test, and compares the result with the baseline. If we change the heap size and the collector together and p99 improves, we do not know which change helped, or whether one of them hurt. A simple experiment log keeps the work honest and reusable.
| Run | Change | p99 | Notes |
|---|---|---|---|
| 0 | baseline | 620 ms | PriceCache.get lock contention |
| 1 | snapshot cache, no lock on read | 290 ms | contention gone |
| 2 | + timeout on price refresh call | 270 ms | no long refresh holds |
| 3 | + heap 70 to 75 percent | 268 ms | within noise, reverted |
| 4 | + batch DB reads for line items | 210 ms | target met |
Notice run 3: the change made no measurable difference, so we reverted it instead of keeping a flag just in case. Each run is repeated at least twice, because latency tests are noisy, and small differences of a few percent should not be trusted from a single run.
6Validate in a Canary Before Rolling Out
A load test is still a model of production. Before rolling out, we deploy the change to a canary, a small share of pods receiving real traffic, and compare its p99 with the rest of the fleet over at least one daily peak. Production has request mixes, data shapes and downstream behaviour that no test captures fully. If the canary meets the target and nothing else gets worse, such as error rate, CPU or memory, we roll out gradually and keep the experiment log with the change, so the next person who tunes this service starts from our evidence instead of from scratch.
7Follow-up questions
Why not just switch to ZGC when p99 is bad?
Because the cause may not be GC at all. If the time is spent waiting on a lock or a slow database query, a different collector changes nothing except memory use and throughput. ZGC is a good answer once the data shows GC pauses are the problem and the latency target is tight.
What is coordinated omission and why does it matter here?
It is a measurement error where a load generator waits for slow responses before sending the next request, so it sends fewer requests during a stall and records fewer slow ones. The measured p99 then looks better than reality. Tools that schedule requests at a fixed rate and measure from the intended send time avoid it.
How long should each experiment run?
Long enough to reach steady state and include the behaviour we care about: after warmup, through several old-generation cycles if GC is involved, typically 20 to 60 minutes. Short tests miss mixed collections and slow drifts.
8Conclusion
In this answer, we followed a tuning method for a missed p99 SLO: define the metric, load and target; reproduce on a production-shaped pod and record a baseline; find where the time goes with traces, JFR and profiles before changing anything; treat GC with allocation and live data fixes in code or heap and collector changes in the JVM; change one thing at a time with a written experiment log; and validate in a canary with production traffic before rollout.
Open with
First I make the goal precise: which endpoint, client or server side, under what load, and the target. Something like p99 of POST orders under 250 milliseconds at 1,200 requests per second, versus 620 today.
Then, if they want more
Then I reproduce it on a pod shaped like production, with realistic data and a load tool that doesn't hide stalls, and record a baseline: latency distribution, throughput, CPU, GC logs, versions and flags. Before changing anything I find where the time goes.
Traces tell me if it's our service or a downstream call; a JFR recording shows GC pauses, lock contention, parks and socket reads; CPU and wall-clock profiles show computing versus waiting. Often it's not GC at all, it's a lock or a slow query.
If GC is the cause, I look at why: allocation rate, live set close to the heap, evacuation failures. Then I choose between reducing allocation or live data in the code, which helps every collector and survives upgrades, and adjusting the heap or collector, like more headroom or ZGC for very tight targets.
Every experiment changes one thing, runs the same test at least twice, and goes into a log, and anything that doesn't help gets reverted. Finally, the winning change goes to a canary with real traffic over a daily peak before a gradual rollout.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21
- 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 "A JVM service misses its p99 latency SLO. Describe your tuning methodology from start to...": https://scrivio-interview-library.netlify.app/java/jvm-tuning/cbf4e2f20f/