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.
On this page
Concept Made Simple
Coffee Chat Question
“How do the modern collectors (Parallel, G1, ZGC, Shenandoah) trade off throughput vs latency, and how do you choose?”
Remember It Faster
Mind Map Answer
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.
- Parallel
- Max throughput, long STW — batch/ETL
- G1 (default)
- Balanced, pause-target, region-based
- ZGC / Shenandoah
- Sub-ms pauses, huge heaps, concurrent
- Serial
- Tiny heaps / single-core / containers
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.
Learn by Doing
Hands-on Keyboard
# 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 ServiceThink Beyond the Expected
What If?
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:
- throughput vs latency trade-off
- Parallel = batch
- G1 = balanced default
- ZGC/Shenandoah = sub-ms, large heap
- choose by SLO then tune
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
- How does G1 achieve its pause target internally?
- How do ZGC/Shenandoah stay concurrent (barriers)?
- How do you measure whether GC is actually your bottleneck?
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?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair