A JVM service has latency spikes every 30–60 seconds; GC logs show "Pause Full (G1 Compaction Pause)" taking 4 seconds.

IntermediateTroubleshootingLatency
Answer

Likely causes → Heap too small for the live set, a memory leak filling old gen, humongous allocations, or -Xmx set close to the container limit so the JVM fights for memory.

Diagnose →

jcmd <pid> GC.heap_info
jstat -gcutil <pid> 1000 10
jcmd <pid> GC.heap_dump /tmp/heap.hprof    # analyze in Eclipse MAT

Fix → Size heap with -XX:MaxRAMPercentage=75 instead of a hard -Xmx, fix the leak, or move to a low-pause collector (ZGC with -XX:+UseZGC) for latency-sensitive services.

Prevent → Export GC pause metrics (Micrometer/JMX) and alert on pause time and old-gen occupancy after GC.

All Real-World Interview questions Roadmap: Interview readiness

More on Latency