Back to Tech
Efficient Java in the cloud with Quarkus
October 28, 2020

As a tech passionate, you certainly know how fast things are moving. Having celebrated its 25th anniversary in 2020, Java has proven to be one of the most popular languages in the world thanks to its multi-platform portability and the richness of the ecosystem. However, Java is also known to be slow and memory consuming compared to other programming languages like C.

For the past months there has been a lot of buzz around Quarkus, an innovative Java framework supposed to bring a solution to these issues, especially the context of cloud environments. Yet another ephemeral Internet buzz or would it really be a game changer that delivers tangible value? In the spirit of answering this question, Carrefour Spain decided to give Quarkus a try. 

Before going into the darkest details of the test, let me tell you a bit more about Quarkus. Quarkus is a Java framework specifically designed for a Kubernetes cluster, tailored to work with modern VMs like GraalVM or HotSpot. Quarkus was thought for serverless environments, optimizing the resources required to run an application.

How does Quarkus work?

Quarkus uses the GraalVM virtual machine to compile Java applications and generate an Kubernetes-native executable file. This file will contain all the application code, the needed Java libraries and the minimally required portion of the JVM, minimizing the dynamic part of Java (“runtime”) as much as possible. In other words : We compile the file -vs. rely only on JIT / code interpretation- and we get rid of everything that is not mandatory to run on the Kubernetes cluster.

During this process, Quarkus reduces the start-up time, the RAM memory consumption and the size of the executable file.

Quarkus is clearly an excellent solution for serverless functions, small pieces of code and microservices that need to be used and started over several times in a short period of time.

Let’s take two examples of serverless functions in the case of retail:

  • Earn and burn for our customers’ loyalty program. In Carrefour we have a huge volume of transactions that are required to activate loyalty mechanisms at the moment of every purchase. This needs to happen really fast to avoid queuing at the check-out or producing a degradation of the digital experience in our e-commerce.
  • Dispatch of the e-ticket. When making a purchase in one of our stores, a digital ticket needs to be generated and sent to the customer’s mobile app in a matter of seconds.

Is Quarkus the solution to everything?

As you can guess, some limitations exist. For instance, some runtime features like Java Agents or profilers -vital to monitor the execution of our code- are reduced. Many of these limitations are mainly due to the product’s youth. Indeed, the first version of Quarkus was released at the end of 2019!

However, the ecosystem is growing every day. You can also use any Java library in Quarkus, even if it has not been migrated yet. However, it would not allow the application to compile “natively” for Kubernetes, hence losing part of the framework advantages. Quarkus provides a web page from where we can explore and download all the libraries you need.

Carrefour Spain’s test: Quarkus vs. Spring Boot

To check if the statements above were correct, we decided to migrate one of our existing microservices to Quarkus and compare it with our existing Java framework for the cloud, Spring Boot. Let me show you how simple the process was and what were the benefits.

We chose a microservice that tapped into our MongoDB database and exposed data to fuel stations through a REST API. This microservice was initially developed using Spring Boot.

The migration from Spring Boot to Quarkus was pretty quick and shouldn’t be a problem for most Java development teams. Among the most notable differences noticed when migrating were the annotations / code metadata: Since some of Spring Boot libraries do not exist in Quarkus, we had to find equivalents in Quarkus and manually modify associated annotations. In our case, the business logic of the selected microservice was pretty simple. However, the migration of an application with a more complex logic and extended use of Spring Boot annotations might not be that easy. 

Once we had our service in production, we evaluated four different KPIs -start-up time, memory use, app size and performance- on both frameworks. Here are the results:

1/ Start-up time

Quarkus: 0,016 seconds.

Spring Boot: 13,85 seconds.

2/ Memory use

Quarkus: 20,7 MB.

Spring Boot: 108 MB.

3/ App size

Quarkus: 3,1 MB.

Spring Boot: 53 MB.

4/ Performance

The number of requests handled and the response time for both microservices was similar.

How will Quarkus help us?

These initial tests confirm that Quarkus may help Carrefour Spain improve both cloud installations as well as on-premise infra.

We often think of Quarkus as a formidable enabler for the cloud. Nevertheless, it must be noted that Quarkus can also be run on classic infra. In Carrefour Spain we have an Openshift (Kubernetes from RedHat) on-premise instance. In this case, Quarkus would allow us to solve some current issues such as:

  • Scalability to face peaks of demand – In key dates like Black Friday or Christmas we would be able to provide the service in case of a significant increase in the number of requests. To compensate for the high start-up time of Spring Boot, we could be proactive and pre-scale some Quarkus services on-prem.
  • Technical efficiency – By reducing resource consumption with the same amount of physical hardware. This is critical for resource-intensive business areas like omnichannel. We have for instance a microservice in charge of aggregating customer purchase transactions for the different channels to display back a consolidated vision in the customer app. This microservice requires at least 10 machine instances and in some cases goes up to 30-40 instances every three months when it comes to distributing the “cheque de ahorro” to our customers.
  • Reliability of critical business processes – Some on-prem microservices like user log-in are critical for our company. Any problem with any of these generates a negative impact on user experience and could be greatly improved reducing start-up time.

In a cloud environment, we are not bound by the physical limits of our infrastructure. This means that we can scale our microservices very quickly and easily. Still, since we pay per usage, it is essential to make the best use of the contracted resources. Two examples below:

  • Efficiency – Rightsizing the cloud environment by better adapting to the increasing number of requests we receive without spending more. This was impossible with Spring Boot, as mentioned above, because the microservice took 13,8 seconds to be ready. With Quarkus we can start-up microservices really fast, thus injecting significant dynamism to the machine.
  • FaaS – Turning microservices into a “Functions as a Service”. Having a very short start-up time would allow us to deploy more generic services in the cloud and only pay for their execution time instead of keeping them up and running 24×7 in the Kubernetes cluster.

The next steps for Carrefour Spain

Our architecture team analyzed all the advantages and disadvantages of using Quarkus as a general framework for microservices in Java. Since the outcomes were highly positive, we decided to generalize Quarkus as part of Carrefour Spain’s tech landscape. 

We launched an effort to create an “archetype” with Quarkus, defining which libraries should be used and creating the necessary standards to work with the new framework.

In parallel, our intention is to start the development of FaaS components using Quarkus, creating mutualized capabilities that can be leveraged by the rest of our company’s applications. Some of the ones we have in mind are:

  • KPIs.
  • Logs.
  • User security.
  • Microservice security.
  • Traceability.
  • Audit.
  • Connectivity with our data lake.

In addition to the new microservices, critical capabilities built on Spring Boot will also be migrated to Quarkus.

The journey to embrace Quarkus will be amazing and full of benefits. This move will help our applications to become scalable, real time, resilient and, all in all, provide a better experience to our customers. Quarkus will also allow us to drastically reduce infrastructure costs.

I encourage every company moving to the cloud like Carrefour to try Quarkus. I would be really interested in sharing experiences and hearing your conclusions!

Check our other tech projects on Horizons.

About the Author

Head Architect of Carrefour Spain David is specialized in modern architectures based on microservices and aims to provide the best solution to business needs. He is passionate about programming paradigms!

What’s new?