The Value of Quarkus

A Developer's Perspective

The Value of Quarkus

This blog is for my talk presented to ING Hub Philippines about the value of Quarkus in business and development. I've shared my personal experience in using this framework and the value it can give to their organization. As of the time of my talk, the framework version was 3.2.0.Final and this is the first LTS version.

The presentation can be accessed in my GitHub Repository: The Value of Quarkus

I've discussed the framework in the following sections:

  • What is Quarkus?

  • Quarkus' Industry Value

  • Performance

    • Quarkus vs Spring Boot

    • JIT vs AOT

    • Metrics

    • AWS Lambda SnapStart

  • Spring Framework Support

  • Sustainability

What is Quarkus?

The framework is called Supersonic. Subatomic. Java. It can be explained into 5 characteristics: Kube-native, Cloud-native, Imperative and Reactive Code, Developer-centric, and Standards.

Kube-native

Quarkus is designed for Kubernetes-based development. It is a framework to leverage the characteristics of Kubernetes specifically for RedHat OpenShift. When developing applications in Quarkus, you're developing as if you're inside the Kubernetes platform due to the usage of YAML files. You can configure the environment directly in Quarkus. Thus, showing Single-step Deployment and Remote Development.

An example YAML file on how to deploy an application and connect to OpenShift automatically.

"%prod":
  quarkus:
    kubernetes-client:
      trust-certs: true
      api-server-url: ${OPENSHIFT_URL}
      token: ${QUARKUS_KUBERNETES_CLIENT_TOKEN}
    openshift:
      route:
        expose: true
      env:
        secrets: mysql
    kubernetes:
      deploy: true
    s2i:
      base-jvm-image: registry.access.redhat.com/ubi8/openjdk-17:1.16-1
    datasource:
      db-kind: mysql
      jdbc:
        url: jdbc:mysql://<SQL Hostname>:3306/demo
      password: ${database-password}
      username: ${database-user}

Cloud-native

Since it is a Kubernetes Java framework, it is optimized to be used in the cloud. It Shows fast startup times, minimal usage of reflection, and support for GraalVM Native compilation. This characteristic is related to the benefits of being a Greener framework.

Imperative and Reactive Code

Quarkus supports both imperative and reactive programming whether in microservices, event-driven microservices, or serverless architectures. You can code HTTP Microservices, Reactive APIs, and Functions. Quarkus has all extensions for that.

Below are some examples of API coding in Quarkus.

AWS Lambda code using API Gateway

@Named("/lambda1")
public class Lambda1 implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {

    @Override
    public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent request, Context context) {
        String httpMethod = request.getHttpMethod();
        String result = "";

        if ("GET".equals(httpMethod)) {
            // Business logic
        }

        return new APIGatewayProxyResponseEvent().withBody("Invoked Lambda")
                        .withStatusCode(200);
    }
}

HTTP Microservices

@Path("/employee")
@ApplicationScoped
public class EmployeeResource {
    @Inject
    EmployeeRepository employeeRepository;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<Employee> getEmployee() {
        return employeeRepository.listAll();
    }
}

Reactive Microservices

@Path("/employee")
@ApplicationScoped
public class EmployeeResource {
    @Inject
    EmployeeRepository employeeRepository;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Multi<Employee> getEmployee() {
        return Multi.createFrom().items(employeeRepository.streamAll());
    }
}

Developer-centric

Quarkus offers a seamless development experience for developers and users. It offers a variety of tools such as live reloading, remote development, Dev UI/Services, Continuous Testing, and Quarkus Extensions.

Dev UI is a local development website typically accessed via localhost:8080. It shows the dependency that you've used in your application and the ability to deploy to a cloud platform like RedHat OpenShift automatically.

Dev Services is Quarkus' ability to give an on-demand environment via TestContainers for common development tools like Databases, Kafka, RabbitMQ, etc. You can check out the documentation in Dev Services

Quarkus Extensions are external libraries integrated into Quarkus CDI. These are from the Quarkus Platform and Quarkiverse

Standards

The framework is backed by industry standards and specifications. Some of these are Vert.x, Eclipse Microprofile, Micrometer, and Jakarta EE.

Quarkus Industry Values

The industry values that it can give are based on cost savings, the reduction of the resources needed to deploy an application, and its environmental impact.

  • Cost Savings: Less memory footprint, fast start-up time, and less disk footprint

  • Speed and Agility: faster time to market using Quarkus Extension and crafted from well-known libraries which can be easily learned

  • Standard and Support: RedHat Build Support for Quarkus, an active community with regular releases in GitHub and based on CNCF technologies

  • Sustainability: Write Greener applications using Quarkus. Due to the minimal reflection and the small memory footprint of Quarkus, the framework shows characteristics of decarbonization.

Performance Metrics

I've presented a comparison of Quarkus to Spring Boot. I compared it to the following metrics:

  • Image Size

    • Spring Boot has a lesser size due to reflection. Quarkus performs build-time compilation causing increased image size.
  • Startup Time

    • Quarkus doesn't need anymore to execute always dynamically the metadata of a program. Thus, improving startup times.
  • Memory Usage

    • Quarkus is optimized to reduce its memory usage consumption. The CDI process of Quarkus uses Ahead of Time compilation to minimize the use of reflection.

AWS Lambda SnapStart

The performance of Quarkus and Spring Boot in response time decreased significantly. Although, Spring Boot was 6x more efficient when integrated with SnapStart. While Quarkus had it 2x more efficient.

Spring Framework Support

Quarkus support a number of annotations of Spring inside the Quarkus CDI (Quarkus ArC). The documentation can be accessed by clicking the link for each bullet. These can be listed as:

Sustainability

Quarkus offer writing greener applications as prescribed by RedHat Greener Application Executive Summary. In this summary, they compare Quarkus to the energy consumption of a single light bulb, startup times, and the carbon dioxide equivalent (CO2-eq) respectively.

Final Thoughts

In this presentation, I've discussed what will be the benefit of using Quarkus from a developer's perspective. It's not just a seamless development experience but the impact that a developer can give on their organization and the environment.

With the increased modernization and migration of legacy applications to the cloud. We can expect that they will consider a developer-friendly and sustainable framework that can optimize their applications in the cloud.