Modern Microservice applications are powering mission critical applications in enterprises. Choosing the right GC strategy plays a key role in influencing the Microservice application’s performance. In this modern world, where we are all used to 1-minute video shorts, we might not have the bandwidth to read the entire post. Thus, to keep the long story short, let me share the key takeaway of this post right here: If your Microservice is less than 32GB heap size then use G1 GC algorithm. If your application’s heap size needs to be greater than 32GB and you are running on Java 21 or above versions, then use ZGC Algorithm. You don’t have to continue to read further, unless you want to learn the rationale for my recommendation and more details.

If you are new to Java GC Concepts, we recommend you learn about Java Garbage Collection fundamentals from this post.

Video

In this video, our Architect Ram Lakshmanan has unpacked the different GC algorithms available in the JVM, explained their unique trade-offs, and provided valuable guidance on how to select the best fit for specific application workloads.

Performance Requirements of Microservice Applications

Modern Microservice applications are expected to have the following performance characteristics:

  1. Low latency (i.e. fast response time)
  2. High throughput (i.e. ability to process lot of transactions in a unit of time)
  3. Scalable (i.e. need to handle varying workload)
  4. Resilient (i.e. Fault Tolerant to withstand any component, environmental outages)
  5. Observable (i.e. Provide deep system insights, centralized logging, real-time monitoring, and proactive alerting)

Here, low latency and high throughput, are two primary characteristics that are influenced by the Garbage Collection behaviour.

GC Algorithms in Open JDK

As of 2025, there are 7 GC algorithms in OpenJDK:

1. Serial GC

2. Parallel GC

3. CMS GC

4. G1 GC

5. ZGC

6. Shenandoah GC

7. Epsilon GC

Out of these 7 GC algorithms, 5 GC algorithms are not suitable for Microservices for the following reasons:

1. Serial GC is the oldest GC algorithm. This algorithm incurs long pause time and affects the latency of the transaction. However, they add very minimal CPU and memory overhead. For Microservices response times are important, thus Serial GC is not a good fit.

2. Parallel GC is a good algorithm that tends to give high GC Throughput; however they incur occasional long GC pauses. Long GC Pauses affect the Microservices/Cloud Apps response times. Thus, Parallel GC is not a good choice.

3. CMS GC algorithm has been deprecated in JDK 9 and removed from JDK 14. Even if you are running on an older version of JDK, it’s not advisable to run on a GC algorithm which has been removed.

4. Shenandoah GC algorithm was originally developed by RedHat and now the generational version of this algorithm is developed by Amazon. Since it’s not officially supported by Oracle/JDK Team, I will shy away from using this algorithm, unless it provides phenomenal results (which you need to validate for your application).

5. Epsilon GC is basically a No-Op GC algorithm. It’s only used for academic or experimental purposes. Production applications can’t be run using this algorithm

Right choice for Microservices: G1 GC and ZGC

There are only 2 good choices in OpenJDK for Microservice applications:

a. G1 GC has been the default GC algorithm since Java 9. G1 GC algorithm strikes a good balance between GC Throughput and GC Pause Time. These are two essential demands for the modern Microservices. If your application’s heap size can be kept under 32BG, then consider using the G1 GC algorithm. If you are looking to learn about G1 GC tuning parameters, you may  refer to this G1 GC Tuning post.

b. ZGC: If you happen to be running on JDK 21 and your application needs more than 32GB of heap size, you should consider using the ZGC algorithm. The ZGC algorithm tends to perform really well when your heap size is very large. If you are looking to learn about ZGC tuning parameters, you may  refer to this ZGC Tuning post. 

Note: Significant performance enhancements have been made to ZGC only from JDK 21 release. ZGC in the earlier releases are not that performant. Thus, if you happen to be running on JDK 21 or below, we recommend evaluating both G1 GC and ZGC algorithms and then make an effective choice. 

If you are looking to tune GC performance, I would like to recommend reading this post: 9 Tips to Reduce GC Pause Time. This post gives high level tips, tricks and best practices to reduce GC pause times.

GCeasy Tool to Study GC Performance

Note: Please conduct proper performance tests and make a decision on which GC algorithm to use. Don’t make your decision based on the information shared in this post.

You should do a GC study before switching to a different GC Settings. Thus we recommend you to study the GC Key Performance Indicators using tools like GCeasy. GCeasy provides necessary recommendations and GC settings to enhance your application’s performance. There is this famous proverb: ‘Proof of the pudding is in the eating’. Similarly, you can also review the sample GC log analysis report generated by the GCeasy tool and experience its output first hand. 

Conclusion

Tuning GC settings brings tremendous performance improvements to your microservices. Several major enterprises have understood the importance of GC tuning and achieved phenomenal performance gains, you can also bring a similar impact to your organization. If you found this post useful, and would like to learn more about GC tuning you, please check out my online ‘JVM Performance Engineering & Troubleshooting Master Class’.