Quarkus, the Cloud Native Java stack
Introduction to Quarkus - Supersonic Subatomic Java
This blog introduces Quarkus, a cloud-native Java stack to the Java fanatics. First, we will discuss all the pitfalls of the existing Java stacks. Then we will arrive at a decision with strong points to adapt Quarkus. And finally, evaluate all the features that Quarkus provides.
Java, the duke who lived.
Java has been a legend when it comes to portability, extendability, maintainability, support and a rich set of libraries. When the product team expects an MVP in the next 2 months, you simply can not scrabble low-level code for accessing database records. And it is not considered DONE until you add those unit tests, integration tests, CI-CD pipelines, monitoring and tracing. For all the above-mentioned necessities Java has marvellous solutions which pretty much makes it the enterprise programming language of the world.
But the supremacy of Java has been questioned when the software industry started its long migration journey to the Cloud. Java developers first met with the shock of not deploying their fat War files to the Application servers. But Spring came to the rescue with embedded application servers. But still, many enterprises did not warm to the idea of running their application on someone else’s computer (The so-called Cloud).
So these companies owned huge servers with humongous RAM memory allowing Java developers to abuse it with outrageous Heap sizes. When the engineers of these companies heard the word ‘Microservices’ they started splitting one huge application into 100s of huge applications.
"If product-microservice is just handling the Create, Read, Update and Delete of one table then why do you need 1GB of RAM to run it?" Questioned the CTOs.Java dudes were caught red-handed with 100GB RAM wasted on a portal that did not even have 100 concurrent users.
Each of these microservices took few seconds to restart and most of them were based on Spring Boot and Spring Cloud frameworks. Every developer added his/her favourite starter to each of these applications without even thinking if it is really needed. This resulted in Huge memory requirements and the Jar was singing when it was packaged (You guessed it right because it was a fat Jar).
- Our applications are huge eating up large RAM space loading lots of classes.
- Our frameworks are based on Reflection.
- Our server startup time is extremely slow in an age when availability is a default measure of backend. Other languages are racing ahead of Java.
- We don’t need the portability feature anymore. We are actually shipping the machine where the code actually works (remember the Docker meme?).
- Software should no longer be a valve radio warming up to perform better. It should be fast right from the first request.
All these problems are inherent in the current Hotspot JVM (Just In Time compilation) and Spring stack (Reflection based) is no longer an option if we want to pound our chest.
To remediate all the above-mentioned problems we need a Java stack that,
- Discards unnecessary classes during compile time (Ahead Of Time compilation).
- Avoid using reflection as much as possible.
- Starts faster as a native application with startup times in milliseconds.
- Packaged as a native application without the need to install JVM in the final Docker.
- Serves the requests at top speed right from the first request received.
Is that even possible with Java? Oh yeah! We are back with a bang y’all!
Quarkus is a Java stack which is Cloud-native and runs on GraalVM and Hotspot. You can imagine it like Java was hit by a bolt of lightning and became Quarkus (Flash reference). Except Quarkus is a stack like Spring, only better.
Right from the inception, Quarkus was developed as a Container First framework. Quarkus avoids reflection as much as possible and that helps GraalVM to compile almost everything needed in compile time. So the final native application generated is lightweight and occupies very little memory when loaded.
GraalVM AOT compilation
GraalVM is a JVM that adds an advanced Ahead Of Time compiler on top of the existing Hotspot JVM. So you can see the GraalVM release has a tag of the actual Hotspot VM it was built on top of. For example version 184.108.40.206 has 2 different downloads, one for JDK 8 and the other JDK 11. The next version will also contain JDK 16. So while building the Quarkus project we need to use the GraalVM if we want a native image.
From the IDE though it works on Hotspot JVM without any need to build the native image. This saves a lot of time as the GraalVM compilation is really slow. 5 mins guaranteed for a vanilla project. But once compiled it is blazing fast like a native application built on C.
Lean Docker image
Quarkus provides a plugin to generate a native image with or without final Docker image generation. Once compiled with GraalVM Quarkus build will emit a native image which can be packaged to a distro less Linux Docker image. We don’t need a JVM to run it and hence the Docker image is very compact. With this, we achieve faster deployments too.
Quarkus also features a NodeJS like auto-reload function which deploys the code immediately when you change the files and save them. This is super cool and the server starts instantaneously in the blink of an eye.
Cloud-native and Microservice standards
Backed by companies like Red Hat, Quarkus is built on microservice frameworks like Microprofile and Vert.X. Quarkus also includes a Kubernetes extension which we can use to easily configure the microservice and prepare them for Cloud. Quarkus can compete on par with microservices built on other languages like Golang or NodeJS (JS).
Imperative and Reactive in one
Quarkus also supports Imperative and Reactive style programming in the same application making it easy to try what’s needed and move to a coherent style based on the team’s decision and expertise.
Quarkus is ahead of the curve, flexing its muscle with a huge list of extensions for database access, messaging, REST APIs and whatnot.
This gives us solid reasons to adopt the cloud-native Java before taking a rash decision of choosing a language that might use you as a guinea pig. Quarkus proves that Java is still sexy, give it a try.