Java / JVM Architecture (Java21) Interview questions
Why should you choose ZGC over G1 for low-latency applications?
Choose ZGC when an application has a hard latency ceiling, such as a trading system or a real-time bidding service, where even occasional pauses in the tens-of-milliseconds range, which G1 can hit under heap pressure, would violate a service-level requirement.
ZGC's concurrent marking and relocation, backed by colored pointers, keep essentially all GC work off the application threads, so its worst-case pause stays sub-millisecond regardless of how large the heap grows - this predictability under scale is exactly what G1's region-based but still partly stop-the-world design cannot guarantee as consistently.
The trade-off worth accepting for that predictability is slightly higher CPU and memory overhead from ZGC's barriers and multi-mapped memory, plus somewhat lower peak throughput than a well-tuned G1 on smaller heaps.
For typical web applications where a rare 50-100ms pause is tolerable, G1 usually remains the better default because it gives comparable or better throughput without ZGC's extra overhead.
More Related questions...