DEV Community

Nevin
Nevin

Posted on

Case Study: Building a Scalable CRUD Application with Quarkus

1. Overview

This case study explores the development of a Person Management System using Quarkus, a Kubernetes-native Java framework optimized for cloud environments. The application demonstrates CRUD operations (Create, Read, Update, Delete) with a MySQL database, leveraging Quarkus' efficiency, developer-friendly tooling, and native compilation capabilities.

2. Project Objectives

  • Build a performant REST API for managing Person entities.
  • Utilize Quarkus' live coding features for rapid development.
  • Demonstrate integration with Hibernate ORM/Panache for simplified database interactions.
  • Package the application as a lightweight JAR and native executable.

3. Technical Architecture

Architecture Diagram

Architecture Diagram

Key Components:

  • MySQL Database: Stores Person records.
  • Hibernate ORM/Panache: Manages persistence layer with active record pattern.
  • RESTEasy: Implements JAX-RS endpoints.
  • SmallRye OpenAPI: Auto-generates OpenAPI documentation.

4. Implementation Highlights

4.1 Data Model

@Entity  
@Table(name = "Person")  
public class Person {  
    @Id  
    @GeneratedValue(strategy = GenerationType.IDENTITY)  
    private Long id;  
    private String name;  
    // Getters/Setters  
}  
Enter fullscreen mode Exit fullscreen mode

Uses Hibernate annotations for ORM mapping with MySQL auto-increment IDs.

4.2 Repository Layer

@ApplicationScoped  
public class PersonRepository implements PanacheRepository<Person> {  
    Person findByName(String name) {  
        return find("name", name).firstResult();  
    }  
}  
Enter fullscreen mode Exit fullscreen mode

Extends PanacheRepository for out-of-the-box CRUD methods while adding custom queries.

4.3 REST Service

@Path("/persons")  
@ApplicationScoped  
public class PersonService {  
    @Inject PersonRepository personRepository;  

    @GET  
    public Response getAllPersons() {  
        return Response.ok(personRepository.listAll()).build();  
    }  

    @POST  
    @Transactional  
    public Response savePerson(Person person) {  
        personRepository.persist(person);  
        return Response.ok(person.getName() + " saved").build();  
    }  
    // PUT, DELETE methods omitted for brevity  
}  
Enter fullscreen mode Exit fullscreen mode

Key Features:

  • Transaction management via @Transactional
  • JAX-RS annotations for endpoint definition
  • JSON serialization/deserialization handled automatically

4.4 Database Configuration

application.properties:

quarkus.datasource.db-kind=mysql  
quarkus.datasource.jdbc.url=jdbc:mysql://localhost:3306/mydb  
quarkus.hibernate-orm.database.generation=update  
Enter fullscreen mode Exit fullscreen mode

Configures MySQL connection and automatic schema updates.

5. Development Workflow

5.1 Live Coding

./mvnw clean compile quarkus:dev  
Enter fullscreen mode Exit fullscreen mode
  • Code changes reflected instantly without restart
  • Access Dev UI at http://localhost:8080/q/dev

5.2 Testing Endpoints

# Create Person  
curl -X POST -H "Content-Type: application/json" \  
  -d '{"name":"John Doe"}' http://localhost:8080/persons  

# Retrieve All  
curl http://localhost:8080/persons  
Enter fullscreen mode Exit fullscreen mode

5.3 Packaging

# Standard JAR  
./mvnw package  

# Native Executable (GraalVM)  
./mvnw package -Dnative  
Enter fullscreen mode Exit fullscreen mode

Result:

  • Uber-JAR size: ~15MB
  • Native executable startup time: ~0.01s

6. Challenges & Solutions

Challenge Quarkus Solution
Database schema management quarkus.hibernate-orm.database.generation=update
Boilerplate CRUD code PanacheRepository base class
Native compilation issues Containerized builds via -Dquarkus.native.container-build=true

7. Results & Metrics

  • API Response Times (10k requests):

    • JVM Mode: Avg 12ms
    • Native Mode: Avg 8ms
  • Memory Usage:

    • JVM Heap: ~120MB
    • Native: ~45MB RSS

8. Conclusion

This project demonstrates Quarkus' strengths in building modern Java applications:

  1. Developer Productivity: Live reload, Dev UI, and simplified Hibernate configuration.
  2. Performance: Subsecond startup times and low memory footprint in native mode.
  3. Cloud Readiness: Container-friendly packaging and native Kubernetes integration.

Future Enhancements:

  • Add frontend with Quarkus Qute templating
  • Implement reactive endpoints with Mutiny

Quarkus Documentation: quarkus.io/guides

This case study demonstrates how Quarkus enables developers to build cloud-native applications that combine traditional Java strengths with modern runtime efficiencies.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay