HardExperience level: 8-15 years2 min read

Choosing a GC: Throughput vs Latency — Interview Questions

Reviewed by Gurusankar M.

Asked inAmazonNetflixGoogleGoldman Sachs
#garbage collection#g1#zgc#shenandoah#latency#throughput
Report issue

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

bash
# 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

Think 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

  1. How does G1 achieve its pause target internally?
  2. How do ZGC/Shenandoah stay concurrent (barriers)?
  3. 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.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.