Quarkus framework: All you need to know

6 min read
April 22, 2024

Java is probably not the first language that comes to your mind when you think of cloud computing

After all, its core concepts are the opposite of those that modern cloud architecture requires.

In this article, we’ll go over what it takes to make Java cloud-friendly and the framework that aims to do that: Quarkus.

What is Quarkus?

Quarkus is an open-source Java framework made specifically to address Java’s limitations when it comes to cloud computing. 

Java’s large artifacts, slow startup time, and high resource usage are a consequence of its optimization for traditional enterprise applications, which aren’t compatible with modern cloud architecture. 

Quarkus enables fast startup, higher speed and performance with its container-based design and framework optimization. 

Better performance and lower memory usage mean lower cost, which is especially important for cloud environments. 

Quarkus also supports standard Java libraries and frameworks, which means there’s no need to put extra time and effort into learning new technologies. 

While it was made for modern cloud architectures, it still supports traditional architectures. 

Now let’s take a look at some of the most important features of Quarkus.

Quarkus: important features

Container-first 

Quarkus aims to optimize application performance by doing processing at build time as much as possible, instead of doing it at runtime. 

Quarkus

This means a longer build time, but also a faster startup and lower memory usage. Reflection calls can be replaced with regular invocations, resulting in even lower memory usage.

Possibility of AOT compilation with GraalVM

A native image contains everything it needs to run, so there’s no need to have a JVM installed. 

It also contains the minimum amount of code required to run because any extra/dead code is analyzed and removed. All of this means compiling applications to native images makes them less resource-intensive and faster to boot.

Class initialization in GraalVM native image generation

Kubernetes-native

Deployment to Kubernetes is done easily and with minimal configuration. Quarkus also provides tools for debugging and metrics for Kubernetes.

Combines reactive and imperative programming

Quarkus is reactive at its core but it offers the capability to implement both imperative and reactive code in the same app. And they’re handled by the same reactive engine.

Easier development

Aside from various tools for code generation, testing and debugging out of the box, and a reduction in boilerplate code usage, Quarkus offers the possibility of hot reloading when running the app in dev mode. 

It will automatically compile and redeploy changes made to Java resource and configuration files when resending a request.

Quarkus vs SpringBoot

How does Quarkus compare to one of the most popular Java frameworks, Spring Boot?

Let’s look at some important differences:

Performance and speed 

Whether using JVM or Native, Quarkus is usually faster. It’s optimized for fast startup and lower memory usage, while Spring Boot is generally heavier and slower.

Size 

Spring Boot is a larger framework, with more dependencies.

Kubernetes-native

Only Quarkus is Kubernetes-native, which makes it more convenient for deployment to Kubernetes.

Developer features 

They both have a variety of features, but Quarkus’s out-of-the-box hot reloading quite stands out.

Ecosystem and maturity 

Spring Boot, being older and massively popular, is the more mature one here, with a larger ecosystem.

So, when choosing between these two frameworks, which should you choose? 

It all depends on your needs and preferences. 

If things like performance, speed, and flexibility are a priority to you (the first two often are when it comes to cloud environments), Quarkus might be the way to go. 

On the other hand, if you prefer an established framework with a lot of resources, support, and tools, you can’t go wrong with Spring Boot.

How to set up Quarkus

Setting up Quarkus is easy. One of the ways to do it is to open a terminal and type:

curl -Ls https://sh.jbang.dev | bash -s - trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/

curl -Ls https://sh.jbang.dev | bash -s - app install --fresh --force quarkus@quarkusio

Or in Powershell:

iex "& { $(iwr https://ps.jbang.dev) } trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/"
iex "& { $(iwr https://ps.jbang.dev) } app install --fresh --force quarkus@quarkusio"

Then restart the shell, and Quarkus is ready for use!

Now, we’ll quickly create an initial project called code-with-quarkus and navigate into it. Run:

quarkus create && cd code-with-quarkus

Let’s take a look at the project structure that we created:

Quarkus project structure

We generated the following files:

  • Four Docker files – Two files for building a container to run in JVM mode and two for native mode.
  • A sample GreetingResource class and accompanying tests
  • Empty application.properties file, which is the sole configuration file for the entire application.
  • Maven structure – This project is, by default, configured to build using Maven, but it’s also possible to use Gradle. All of the dependencies required to start the project are already included in the pom.xml file.

So let’s start it in development mode with:

quarkus dev

The app is now listening at localhost:8080 (by default).

Additionally, to illustrate the hot reloading feature, we’ll add a new method to the GreetingResource class:

03 QkYOGfgbKAX8s7BXqQdxv58X8sQrK2u

And run a GET request:

iLIBFk6g5W57qUglZ WB0TaUy24DG DEuJhRosPuO lp4LVDpCsz8H7E3HWs 3Qa8hgZXsNQrTcS2Lc0SC343ksLWUPA87UGpPnFzY1e5 ZWbEIRgL BhIlRviyDeT B9GE1vUzWayiPC7V6NXZjwbQ

The initial response time is higher because the compiling and deployment were triggered.

If we run the request again, we’ll get a much faster response:

We’ve shown how easy it is to set up Quarkus and get started with developing an app, and how convenient the hot reloading feature is.

Conclusion

In conclusion, Quarkus offers the ability to build fast and lightweight applications. 

That, along with easier deployment, makes it ideal for Kubernetes or cloud-native projects. 

However, since it’s so flexible, its benefits can be utilized for any kind of app.

Quarkus’s inclusion of existing frameworks, libraries, and developer features such as hot reloading makes it attractive to developers and increases their productivity.

If you’d like to read more about all things tech, check out our blog!

Categories
Written by

Dajana Radocaj

Java Developer

Related articles