Choosing a GC: Throughput vs Latency β Interview Questions
Reviewed by Gurusankar M.
β‘ Short Answer
It's a throughput-vs-latency trade-off. Parallel GC maximises throughput but has long stop-the-world pauses β good for batch. G1 (the default) balances the two with region-based, mostly-concurrent collection and a pause-time target β good for general server apps. ZGC and Shenandoah are concurrent, region-based collectors that keep pauses sub-millisecond even on multi-hundred-GB heaps β pick them for latency-sensitive services with large heaps, at a small throughput cost.
βCoffee Chat Question
Concept Made Simple
βHow do the modern collectors (Parallel, G1, ZGC, Shenandoah) trade off throughput vs latency, and how do you choose?β
π§ Mind Map Answer
Remember It Faster
There's no 'best' collector β there's the right one for your SLO. Every collector trades some combination of pause time, throughput, footprint, and heap-size ceiling.
Rule of thumb: batch β Parallel, typical service β G1, low-latency / very large heap β ZGC or Shenandoah, tiny footprint β Serial. Measure allocation rate and pause SLO before switching.
Key takeaway: choose by SLO, then tune. Reach for the deep-dive pages (G1 internals, ZGC) once you've picked the family that matches your latency budget.
β¨οΈHands-on Keyboard
Learn by Doing
# Batch job: favour throughput
java -XX:+UseParallelGC -Xmx8g BatchJob
# Latency-sensitive service on a large heap
java -XX:+UseZGC -Xmx64g -XX:+ZGenerational Service
# G1 (default) with an explicit pause target
java -XX:MaxGCPauseMillis=100 -Xmx8g Serviceπ₯What If?
Think Beyond the Expected
A trading service has a 200GB heap and a 1ms pause SLO β which collector, and why not G1?
ZGC or Shenandoah. G1's stop-the-world pauses grow with heap and live-set size, so at 200GB it can't hold a 1ms SLO. ZGC/Shenandoah do their marking, relocation, and reference processing concurrently with the application using load/read barriers, keeping pauses sub-millisecond almost independently of heap size β the exact profile a large, latency-critical service needs. You accept a modest throughput/CPU overhead for that predictability.
πReal World
Nightly analytics or Spark jobs run Parallel GC to finish faster; a typical Spring Boot API runs the G1 default and rarely needs to change; latency-critical trading, ad-serving, and gaming backends on big heaps move to ZGC/Shenandoah specifically to kill tail-latency pauses that show up as p99 spikes.
π―Interviewer's Expectation
Keywords they're listening for:
β οΈCommon Mistakes
- βAssuming one collector is universally fastest
- βUsing G1 for a very large heap with tight pause SLOs
- βSwitching collectors without measuring allocation rate/pauses
β Best Practices
- βPick the collector family from your latency SLO
- βRight-size the heap before blaming the collector
- βVerify with GC logs / JFR after any change
πFollow-up Questions
- 1How does G1 achieve its pause target internally?
- 2How do ZGC/Shenandoah stay concurrent (barriers)?
- 3How do you measure whether GC is actually your bottleneck?
π§©Related Technologies
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly β AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Garbage Collection (Advanced Java) Interview question: "How do the modern collectors (Parallel, G1, ZGC, Shenandoah) trade off throughput vs latency, and how do you choose?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.