Chuyển đến nội dung chính

Lesson 1: What is Quarkus? — Supersonic Subatomic Java for Microservices

Overview of Quarkus, build-time optimization architecture, comparison of Quarkus vs Spring Boot for microservices, Quarkus Extensions ecosystem, <1 second startup demo.

💻 Programming — Lesson 0 Lesson 1: What is Quarkus? — Supersonic Subatomic Java for Microservices

Quarkus Microservices: From Basics to Production

Part 1: Quarkus Platform & Project Setup

xdev.asia

Introduction

In the Cloud Native world, boot speed and memory consumption determine the cost of running a microservices system. Quarkus — "Supersonic Subatomic Java" — is a framework developed from the ground up by Red Hat specifically for Kubernetes and GraalVM, with the ability to start up in under 1 second and use only ~50MB of RAM in native mode.

This series will take you from the first "Hello World" article to an E-Commerce system consisting of 5 microservices running in production.

What is Quarkus?

Quarkus is a Kubernetes-native Java framework designed for JVM (HotSpot) and GraalVM Native Image. The goal: help Java become the leading language for serverless, microservices, and container-based workloads.

Outstanding features

FeaturesDescription
Build-time optimizationDependency analysis, configuration, annotation processing at build time — not runtime
Dev ServicesAutomatically start PostgreSQL, Kafka, Keycloak with Testcontainers when dev/test
Live CodingChange code → save → refresh browser, no need to restart
Unified Imperative + ReactiveSupports both blocking (imperative) and non-blocking (reactive) in the same project
GraalVM NativeCompile into native executable — startup <50ms, RAM ~50MB
Extensions Ecosystem600+ extensions for every need: Hibernate, Kafka, gRPC, Keycloak...

Build-Time Optimization Architecture

Unlike Spring Boot, which handles everything at runtime (classpath scanning, reflection, proxy generation), Quarkus does most of the work at build time:

┌─────────────────────────────────────────────────┐
│              TRADITIONAL FRAMEWORK              │
│                                                 │
│  Start JVM → Load Classes → Scan Classpath →    │
│  Process Annotations → Build Dependency Graph → │
│  Create Proxies → Ready (~5-30 giây)           │
└─────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────┐
│              QUARKUS (Build-Time)                │
│                                                 │
│  BUILD: Scan → Analyze → Generate Bytecode →    │
│         Create Static Init Code                 │
│                                                 │
│  RUN:   Load Pre-computed Metadata → Ready      │
│         (~0.5-1 giây JVM, <0.05 giây Native)   │
└─────────────────────────────────────────────────┘

Why is build-time important for Microservices?

  1. Fast Scale-out — Kubernetes needs to spin-up new pods in seconds
  2. Serverless/FaaS — Cold start determines user experience
  3. Resource efficiency — 100 micro-instances x 50MB << 100 x 500MB
  4. Cost optimization — Cloud billing calculated based on CPU/RAM usage

Quarkus vs Spring Boot — Realistic Comparison

CriteriaQuarkus 3.xSpring Boot 3.x
Startup (JVM)~0.5-1s~3-8s
Startup (Native)~0.02-0.05s~0.1-0.3s (Spring AOT)
RSS Memory (JVM)~80-120MB~200-400MB
RSS Memory (Native)~30-60MB~80-150MB
Dev ExperienceDev Services, Live Coding, Dev UISpring DevTools, Initializr
Ecosystem600+ extensions300+ starters
CommunityGrowing strongVery large, mature
Learning curveAverage (CDI, MicroProfile)Low (familiar)
Native supportFirst-class, few issuesMuch improved but still limited
ReactiveMutiny (native) + Vert.xWebFlux (Project Reactor)

When to choose Quarkus?

  • Build new microservices (greenfield) for Kubernetes
  • Need quick startup for serverless/FaaS
  • Want to optimize cloud costs (less RAM, less CPU)
  • Team is familiar with Jakarta EE / MicroProfile
  • Requires native executable with GraalVM

When to choose Spring Boot?

  • Migrate existing monolith to microservices
  • The team has deep Spring experience
  • Needs a large ecosystem and large community support
  • Application startup time is not important

CDI & MicroProfile — Standard platform

Quarkus is based on two open standards, not a proprietary API:

CDI (Contexts and Dependency Injection)

CDI is the Jakarta EE standard for dependency injection. Quarkus uses ArC — CDI engine to process at build time:

// Injection cơ bản
@ApplicationScoped  // Singleton trong app
public class ProductService {

    @Inject
    ProductRepository productRepo;

    @Inject
    @ConfigProperty(name = "app.max-products",
        defaultValue = "1000")
    int maxProducts;

    public List<Product> listActive() {
        return productRepo.findActive();
    }
}

// Popular CDI Scopes
@ApplicationScoped // 1 instance / app
@RequestScoped // 1 instance / HTTP request
@SessionScoped // 1 instance / session
@Dependent // New each injection
@Singleton // Like @ApplicationScoped but without proxy

ArC vs Spring DI: ArC analyzes the entire dependency graph at build time → removes unused beans → reduces memory + startup.

MicroProfile

Set of specs for microservices, fully implemented by Quarkus:

SpecQuarkus ExtensionFunction
ConfigBuilt-inType-safe configuration, multiple sources
REST Clientquarkus-rest-clientType-safe HTTP client
Fault Tolerancequarkus-smallrye-fault-tolerance@Retry, @CircuitBreaker, @Fallback
Healthquarkus-smallrye-healthLiveness, Readiness, Startup probes
Metricsquarkus-micrometerApplication & JVM metrics
OpenAPIquarkus-smallrye-openapiSwagger documentation
JWT Authquarkus-smallrye-jwtJWT token parsing & validation
OpenTelemetryquarkus-opentelemetryDistributed tracing

Benefits: code written according to MicroProfile specs portable between Quarkus, Open Liberty, Payara, WildFly.

Quarkus 3.34 — Latest Features (2026)

FeaturesDescription
Virtual Threads (Loom)@RunOnVirtualThread — non-blocking performance with imperative code
Dev Services 2.0Automatically provision any container, not just built-in
Unified CLIquarkus dev, quarkus build, quarkus deploy
Improved NativeBuild time reduced by ~40%, supports more libraries
WebSocket NextNew, annotation-driven WebSocket server/client API
Langchain4jAI/LLM integration native
Hibernate ORM 7Jakarta Persistence 3.2, improved performance
Security improvementsOIDC multi-tenancy, fine-grained RBAC
// Virtual Threads — new in Quarkus 3.x
@Path("/api/v1/products")
public class ProductResource {

    @GET
    @RunOnVirtualThread // Run on virtual thread
    publicList<Product> listProducts() {
        // Blocking code but not blocking OS thread
        return Product.listAll();
    }
}

Quarkus Extensions Ecosystem

Extensions are how Quarkus integrates libraries. Each extension is optimized for build-time processing:

# Find extensions
quarkus extension list
quarkus extension list --search=postgres

# Add extension to project
quarkus extension add quarkus-rest-jackson
quarkus extension add quarkus-hibernate-orm-panache
quarkus extension add quarkus-jdbc-postgresql
quarkus extension add quarkus-oidc
quarkus extension add quarkus-smallrye-reactive-messaging-kafka

Main Extensions in this series

ExtensionFunction
quarkus-rest-jacksonREST API with JSON serialization
quarkus-hibernate-orm-panacheSimplified ORM (Active Record / Repository)
quarkus-jdbc-postgresqlJDBC driver cho PostgreSQL
quarkus-flywayDatabase schema migration
quarkus-oidcOpenID Connect / Keycloak integration
quarkus-smallrye-reactive-messaging-kafkaApache Kafka messaging
quarkus-grpcgRPC server/client
quarkus-smallrye-fault-toleranceCircuit Breaker, Retry, Fallback
quarkus-opentelemetryDistributed tracing
quarkus-micrometer-registry-prometheusMetrics with Prometheus
quarkus-smallrye-healthHealth checks
quarkus-redis-clientRedis caching
quarkus-kubernetesAuto-generate K8s manifests
quarkus-container-image-jibBuild container image

Demo: Hello Quarkus — First start

# Install Quarkus CLI (needs Java 17+)
# macOS
brew install quarkusio/tap/quarkus

# Linux (SDKMAN)
sdk install quarkus

# Create project
quarkus create app com.xdev:hello-quarkus \
  --extension='rest-jackson' \
  --java=21

cd hello-quarkus

# Run Dev Mode
quarkus dev

Result:

__ ____ __ _____ ___ __ ____ ______
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2026-04-03 10:00:00,123 INFO  [io.quarkus] (Quarkus Main Thread)
  hello-quarkus 1.0.0-SNAPSHOT on JVM (powered by Quarkus 3.34.x)
  started in 0.876s. Listening on: http://localhost:8080

Tests paused
Press [h] for more options>

0.876 seconds — compared to 5-10 seconds for equivalent Spring Boot.

Hello REST Endpoint

package com.xdev;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello from Quarkus!";
    }
}
curl http://localhost:8080/hello
# Hello from Quarkus!

E-Commerce system architecture (Preview)

In this series, we will build:

┌─────────────┐ ┌──────────────┐ ┌──────────────┐
│ Browser / │────▶│ API Gateway │────▶│ Keycloak │
│ Mobile App │ │ (Nginx) │ │ (Auth) │
└─────────────┘ └──────┬───────┘ └──────────────┘
                           │
          ┌────────────────┼────────────────┐
          │ │ │
          ▼ ▼ ▼
   ┌──────────┐ ┌──────────┐ ┌──────────┐
   │ Product │ │ Order │ │ Payment │
   │ Service │ │ Service │ │ Service │
   │ │ │ │ │ │
   │ Quarkus │ │ Quarkus │ │ Quarkus │
   │ REST+gRPC│ │ REST │ │ REST │
   └────┬─────┘ └────┬─────┘ └────┬─────┘
        │ │ │
        ▼ ▼ ▼
   ┌──────────┐ ┌──────────┐ ┌──────────┐
   │PostgreSQL│ │PostgreSQL│ │PostgreSQL│
   │(Products)│ │(Orders) │ │(Payments)│
   └──────────┘ └──────────┘ └──────────┘
                        │
                   ┌────┴────┐
                   │ Kafka │
                   │ (Events)│
                   └────┬────┘
                        │
                        ▼
                ┌──────────────┐
                │ Notifications │
                │ Service │
                │ (Quarkus) │
                └──────────────┘

5 Services:

  1. Product Service — Manage products, categories, inventory
  2. Order Service — Order processing, state machine
  3. Payment Service — Payment, transaction log
  4. Notification Service — Email/SMS notifications
  5. User Service (Keycloak) — Identity & Access Management

Exercise

  1. Install JDK 21+ and Quarkus CLI on local machine
  2. Create a Quarkus project with the extension rest-jackson
  3. Write endpoints GET /api/info returns JSON {"framework": "Quarkus", "version": "3.34"}
  4. Compare startup time between Quarkus and an equivalent Spring Boot project
  5. Try inject @ConfigProperty and change the value in application.properties — observe live reload
  6. List all available extensions: quarkus extension list --search=rest — choose 3 extensions you want to learn about

Key Concepts to remember

┌──────────────────────────── ─────────────────────────────┐
│ Quarkus Mental Model │
│ │
│ ┌──────────────┐ ┌──────────────┐ │
│ │ Build Time │───▶│ Runtime │ │
│ │ │ │ │ │
│ │ • Classpath │ │ • Load pre- │ │
│ │ scanning │ │ computed │ │
│ │ • Annotation │ │ metadata │ │
│ │ processing │ │ • Execute │ │
│ │ • Bytecode │ │ static │ │
│ │ generation │ │ init │ │
│ │ • Dead code │ │ • Start HTTP │ │
│ │ removal │ │ server │ │
│ │ │ │ │ │
│ │ (slow, once)│ │ (fast!) │ │
│ └──────────────┘ └──────────────┘ │
│ │
│ Jakarta EE Standards MicroProfile Standards │
│ ┌─────────────────┐ ┌─────────────────────┐ │
│ │ • CDI (ArC) │ │ • Config │ │
│ │ • Jakarta REST │ │ • REST Client │ │
│ │ • Persistence │ │ • Fault Tolerance │ │
│ │ • Bean Validation│ │ • Health / Metrics │ │
│ │ • Security │ │ • OpenAPI / JWT │ │
│ └─────────────────┘ └─────────────────────┘ │
└──────────────────────────── ─────────────────────────────┘

Summary

  • Quarkus is a Java framework designed specifically for Cloud Native & Kubernetes
  • Build-time optimization helps startup <1 second, low RAM
  • Dev Services automatically provision infrastructure during development
  • Compared to Spring Boot: Quarkus is faster, lighter, but Spring Boot has a larger ecosystem
  • This series builds a practical E-Commerce Platform system with 5 microservices

Next article: Creating Quarkus Project — CLI, Dev Mode, Dev UI & Live Coding.