Skip to content

Latest commit

Β 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Microservices with gRPC & Quarkus

Java Quarkus gRPC Docker License: MIT

A production-ready microservices architecture demonstrating inter-service communication with gRPC, built on Quarkus (Supersonic Subatomic Java). This project showcases modern backend engineering patterns for cloud-native applications.


πŸ“ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        CLIENT                               β”‚
β”‚                   (HTTP REST / curl)                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚ HTTP/REST
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    API GATEWAY                              β”‚
β”‚                   :8080 (REST)                              β”‚
β”‚              Quarkus REST Client                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚ gRPC                  β”‚ gRPC
               β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    USER SERVICE      β”‚   β”‚   ORDER SERVICE      β”‚
β”‚     :9000 (gRPC)     β”‚   β”‚    :9001 (gRPC)      β”‚
β”‚     :8081 (HTTP)     β”‚   β”‚    :8082 (HTTP)      β”‚
β”‚                      β”‚   β”‚                      β”‚
β”‚  - CreateUser        β”‚   β”‚  - CreateOrder       β”‚
β”‚  - GetUser           β”‚   β”‚  - GetOrder          β”‚
β”‚  - ListUsers         β”‚   β”‚  - ListOrdersByUser  β”‚
β”‚  - UpdateUser        β”‚   β”‚  - UpdateOrderStatus β”‚
β”‚  - DeleteUser        β”‚   β”‚  - DeleteOrder       β”‚
β”‚                      β”‚   β”‚                      β”‚
β”‚  [In-Memory Store]   β”‚   β”‚  [In-Memory Store]   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Layer Technology Purpose
Framework Quarkus 3.x Supersonic Java runtime
Communication gRPC + Protocol Buffers Efficient inter-service RPC
API REST (JAX-RS) Public-facing HTTP endpoints
Serialization Protobuf 3 Type-safe binary serialization
Build Maven 3.9 Dependency management
Container Docker + Docker Compose Local orchestration
Java Java 17 LTS runtime

πŸ“ Project Structure

grpc-microservices-quarkus/
β”œβ”€β”€ proto/                          # Shared Protobuf definitions
β”‚   β”œβ”€β”€ user.proto                  # User service contract
β”‚   └── order.proto                 # Order service contract
β”‚
β”œβ”€β”€ user-service/                   # User microservice
β”‚   β”œβ”€β”€ src/main/
β”‚   β”‚   β”œβ”€β”€ java/com/portfolio/user/
β”‚   β”‚   β”‚   β”œβ”€β”€ grpc/               # gRPC service implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ resource/           # REST endpoints (health, metrics)
β”‚   β”‚   β”‚   └── service/            # Business logic
β”‚   β”‚   β”œβ”€β”€ proto/                  # Local proto files
β”‚   β”‚   └── resources/
β”‚   β”‚       └── application.properties
β”‚   └── pom.xml
β”‚
β”œβ”€β”€ order-service/                  # Order microservice
β”‚   β”œβ”€β”€ src/main/
β”‚   β”‚   β”œβ”€β”€ java/com/portfolio/order/
β”‚   β”‚   β”‚   β”œβ”€β”€ grpc/               # gRPC service implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ resource/           # REST endpoints
β”‚   β”‚   β”‚   └── service/            # Business logic
β”‚   β”‚   β”œβ”€β”€ proto/
β”‚   β”‚   └── resources/
β”‚   β”‚       └── application.properties
β”‚   └── pom.xml
β”‚
β”œβ”€β”€ api-gateway/                    # REST Gateway
β”‚   β”œβ”€β”€ src/main/
β”‚   β”‚   β”œβ”€β”€ java/com/portfolio/gateway/
β”‚   β”‚   β”‚   β”œβ”€β”€ client/             # gRPC stub clients
β”‚   β”‚   β”‚   β”œβ”€β”€ dto/                # Data transfer objects
β”‚   β”‚   β”‚   └── resource/           # REST controllers
β”‚   β”‚   β”œβ”€β”€ proto/
β”‚   β”‚   └── resources/
β”‚   β”‚       └── application.properties
β”‚   └── pom.xml
β”‚
β”œβ”€β”€ docker-compose.yml              # Full stack orchestration
β”œβ”€β”€ docs/
β”‚   └── api-guide.md                # API documentation
└── README.md

πŸš€ Quick Start

Prerequisites

  • Java 17+
  • Maven 3.9+
  • Docker & Docker Compose

Option 1: Docker Compose (Recommended)

# Clone the repository
git clone https://github.com/YOUR_USERNAME/grpc-microservices-quarkus.git
cd grpc-microservices-quarkus

# Build and start all services
docker-compose up --build

# Verify services are running
curl http://localhost:8080/health

Option 2: Run Each Service Manually

Terminal 1 β€” User Service

cd user-service
./mvnw quarkus:dev -Dquarkus.http.port=8081

Terminal 2 β€” Order Service

cd order-service
./mvnw quarkus:dev -Dquarkus.http.port=8082

Terminal 3 β€” API Gateway

cd api-gateway
./mvnw quarkus:dev -Dquarkus.http.port=8080

πŸ“‘ API Endpoints

Users

Method Endpoint Description
POST /api/users Create a new user
GET /api/users List all users
GET /api/users/{id} Get user by ID
PUT /api/users/{id} Update user
DELETE /api/users/{id} Delete user

Orders

Method Endpoint Description
POST /api/orders Create a new order
GET /api/orders List all orders
GET /api/orders/{id} Get order by ID
GET /api/orders/user/{userId} Get orders by user
PUT /api/orders/{id}/status Update order status
DELETE /api/orders/{id} Delete order

πŸ§ͺ Testing the API

# 1. Create a user
curl -X POST http://localhost:8080/api/users -H "Content-Type: application/json" -d "{\"name\":\"Budi Santoso\",\"email\":\"budi@example.com\"}"

# 2. List all users
curl http://localhost:8080/api/users

# 3. Create an order for user ID 1
curl -X POST http://localhost:8080/api/orders -H "Content-Type: application/json" -d "{\"userId\":\"1\",\"productName\":\"Laptop ASUS\",\"quantity\":1,\"price\":12000000}"

# 4. Get orders by user
curl http://localhost:8080/api/orders/user/1

# 5. Update order status
curl -X PUT http://localhost:8080/api/orders/1/status -H "Content-Type: application/json" -d "{\"status\":\"SHIPPED\"}"

πŸ”‘ Key Concepts Demonstrated

1. Protocol Buffers (Protobuf)

  • Defining service contracts with .proto files
  • Strongly-typed request/response messages
  • Code generation for Java stubs

2. gRPC Server (Quarkus)

  • Implementing generated ImplBase classes
  • Unary RPC calls
  • StreamObserver pattern for async responses

3. gRPC Client

  • Using @GrpcClient injection
  • Blocking stub calls from REST handlers
  • Error propagation across service boundaries

4. API Gateway Pattern

  • Single entry point for all client requests
  • Protocol translation: REST ↔ gRPC
  • Response aggregation

5. Cloud-Native Readiness

  • Health check endpoints (/q/health)
  • Metrics endpoint (/q/metrics)
  • Docker-optimized builds

πŸ“Š gRPC vs REST Comparison

Feature gRPC REST
Protocol HTTP/2 HTTP/1.1
Payload Binary (Protobuf) Text (JSON)
Contract Strict (.proto) Optional (OpenAPI)
Performance ~7x faster Baseline
Streaming Native support Polling/SSE
Code Gen Auto-generated Manual


⭐ If this helped you understand gRPC with Quarkus, please give it a star!

About

microservices with gRPC + Quarkus | Java 17 | Docker

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages