A production-style microservices backend with auto-scaling, Redis caching, and Kubernetes orchestration β built entirely with free, open-source tools.
Client (Postman/K6)
β
βΌ
ββββββββββββββββββββ
β API Gateway β :8080 / NodePort 30080
β (JWT Issue/Val) β
ββββββββββ¬ββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
βProduct Serviceβ β Order Serviceβ β User Service β
β :8081 β β :8082 β β :8083 β
β Redis Cache β β β calls β β PostgreSQL β
β PostgreSQL β β Product β β (Auth data) β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β β β
βΌ βΌ βΌ
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
β PostgreSQL β β Redis β β Monitoring β
β :5432 β β :6379 β β (Actuator) β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ
ecommerce-cloud-native/
βββ api-gateway/ # Spring Cloud Gateway + JWT
β βββ src/main/java/...
β βββ src/main/resources/application.yml
β βββ pom.xml
β βββ Dockerfile
βββ product-service/ # Product CRUD + Redis caching
β βββ src/main/java/...
β βββ src/main/resources/application.yml
β βββ pom.xml
β βββ Dockerfile
βββ order-service/ # Order management
β βββ src/main/java/...
β βββ src/main/resources/application.yml
β βββ pom.xml
β βββ Dockerfile
βββ k8s/ # Kubernetes manifests
β βββ namespace.yaml
β βββ configmap.yaml
β βββ secrets.yaml
β βββ gateway/ # Deployment, NodePort, HPA
β βββ product/ # Deployment, ClusterIP, HPA
β βββ order/ # Deployment, ClusterIP, HPA
β βββ postgres/ # Deployment, ClusterIP, PVC
β βββ redis/ # Deployment, ClusterIP
βββ load-test/
β βββ k6-script.js # K6 load test (500 VUs)
βββ docker-compose.yml # Local development
βββ init-db.sql # PostgreSQL init script
- Docker Desktop
- Java 17
- Maven 3.9+
# Start PostgreSQL and Redis only (for local Maven run)
docker-compose up postgres redis -d
# OR start everything (requires Docker images to be built)
docker-compose up --build -d# Terminal 1 β Product Service
cd product-service
mvn spring-boot:run
# Terminal 2 β Order Service
cd order-service
mvn spring-boot:run
# Terminal 3 β API Gateway
cd api-gateway
mvn spring-boot:runcurl -X POST http://localhost:8080/auth/token \
-H "Content-Type: application/json" \
-d '{"username":"testuser","password":"test123"}'# Create a product
curl -X POST http://localhost:8081/products \
-H "Content-Type: application/json" \
-d '{"name":"Laptop","description":"Gaming Laptop","price":999.99,"stockQuantity":100}'
# Get all products (try twice - 2nd call is served from Redis cache)
curl http://localhost:8080/products
# Create an order (requires JWT)
TOKEN="<your-jwt-token>"
curl -X POST http://localhost:8080/orders \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"productId":1,"quantity":2,"customerName":"John Doe"}'- Product Service: http://localhost:8081/swagger-ui.html
- Order Service: http://localhost:8082/swagger-ui.html
minikube start --memory=4096 --cpus=4minikube addons enable metrics-server
kubectl get deployment metrics-server -n kube-system # Wait until Ready# Point Docker to Minikube's daemon
eval $(minikube docker-env) # Linux/Mac
# OR on Windows PowerShell:
# minikube docker-env | Invoke-Expression
# Build all service images
docker build -t api-gateway:1.0.0 ./api-gateway
docker build -t product-service:1.0.0 ./product-service
docker build -t order-service:1.0.0 ./order-service# Create namespace, secrets, and configmap first
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/secrets.yaml
kubectl apply -f k8s/configmap.yaml
# Deploy infrastructure
kubectl apply -f k8s/postgres/
kubectl apply -f k8s/redis/
# Wait for DB to be ready
kubectl wait --for=condition=ready pod -l app=postgres -n ecommerce --timeout=120s
# Deploy microservices
kubectl apply -f k8s/gateway/
kubectl apply -f k8s/product/
kubectl apply -f k8s/order/# Check all pods
kubectl get pods -n ecommerce
# Check services
kubectl get services -n ecommerce
# Check HPAs
kubectl get hpa -n ecommerce
# Get gateway URL
minikube service api-gateway -n ecommerce --url# Windows (Chocolatey)
choco install k6
# Or download from https://k6.io/docs/get-started/installation/# Against local Docker Compose
k6 run load-test/k6-script.js
# Against Kubernetes (get URL first)
MINIKUBE_URL=$(minikube service api-gateway -n ecommerce --url)
k6 run -e GATEWAY_URL=$MINIKUBE_URL load-test/k6-script.js# Terminal 1: Watch HPA
kubectl get hpa -n ecommerce -w
# Terminal 2: Watch pods
kubectl get pods -n ecommerce -w
# Terminal 3: Run load test
k6 run load-test/k6-script.jsExpected behavior:
- Pod count stays at 1 initially
- After CPU > 60%, new pods are created (up to 5)
- After load ends, pods scale back down after ~2 minutes
| User | Password | Role |
|---|---|---|
| admin | admin | ADMIN |
| user | user | USER |
| testuser | test123 | USER |
Protected routes (require JWT): POST /products, PUT /products, DELETE /products, all /orders/**
Public routes: GET /products/**, GET /auth/**
| Method | Path | Auth | Description |
|---|---|---|---|
| POST | /auth/token | β | Get JWT token |
| GET | /products | β | List all products |
| GET | /products/{id} | β | Get product by ID |
| POST | /products | β | Create product |
| PUT | /products/{id} | β | Update product |
| DELETE | /products/{id} | β | Delete product |
| POST | /orders | β | Create order |
| GET | /orders | β | List all orders |
| GET | /orders/{id} | β | Get order by ID |
| Layer | Technology |
|---|---|
| Language | Java 17 |
| Framework | Spring Boot 3.2 |
| Gateway | Spring Cloud Gateway |
| Database | PostgreSQL 15 |
| Cache | Redis 7 |
| Containerization | Docker |
| Orchestration | Kubernetes (Minikube) |
| Auto-Scaling | HPA + Metrics Server |
| Load Testing | K6 |
| API Docs | Swagger UI (SpringDoc) |
β
Microservices Architecture β 3 independent services
β
Redis Caching β @Cacheable + @CacheEvict with 10-min TTL
β
Java Serialization β Products implement Serializable for Redis
β
Multi-Stage Docker Builds β Minimal JRE 17 runtime images
β
Kubernetes HPA β Scales 1β5 pods at 60% CPU
β
Health Probes β Readiness/liveness on all services
β
Resource Limits β Prevents CPU/memory abuse
β
Global Exception Handling β Structured error responses
β
JWT Security β Token validation at gateway, user headers forwarded