A comprehensive cloud-native microservices application demonstrating modern enterprise architecture patterns with Spring Boot, Docker, Kubernetes, and observability tools.
This project showcases a complete microservices ecosystem with:
- API Gateway with Resilience4J circuit breaker
- Service Discovery and registration
- Event-driven architecture with Kafka
- Database per service pattern
- Monitoring and observability with Grafana, Prometheus, and Tempo
- Containerization with Docker
- Orchestration with Kubernetes
- 🔐 Authentication & Authorization: Secure service-to-service communication
- 🔄 Circuit Breaker: Fault tolerance with Resilience4J
- 📊 Monitoring: Real-time metrics with Prometheus and Grafana
- 🔍 Distributed Tracing: Request tracing with Tempo
- 📨 Async Communication: Event-driven messaging with Kafka
- 🐳 Containerized: Docker and Kubernetes ready
- 📈 Scalable: Horizontal scaling capabilities
- 🎯 Service Discovery: Automatic service registration and discovery
- Services
- Tech Stack
- Getting Started
- Docker Deployment
- Kubernetes Deployment
- Monitoring
- API Documentation
- Contributing
- License
| Service | Port | Description | Technology |
|---|---|---|---|
| API Gateway | 8080 | Entry point, routing, load balancing | Spring Cloud Gateway |
| Product Service | 8081 | Product catalog management | Spring Boot, MySQL |
| Order Service | 8082 | Order processing and management | Spring Boot, PostgreSQL |
| Inventory Service | 8083 | Stock and inventory tracking | Spring Boot, MongoDB |
| Notification Service | 8084 | Email and SMS notifications | Spring Boot, Kafka |
| Auth Server | 8085 | Authentication and authorization | Spring Security, JWT |
- Java 17+ - Programming language
- Spring Boot 3.x - Application framework
- Spring Cloud - Microservices patterns
- Spring Security - Authentication & authorization
- Maven - Build automation tool
- MySQL - Product service database
- PostgreSQL - Order service database
- MongoDB - Inventory service database
- Apache Kafka - Event streaming platform
- Grafana - Visualization and dashboards
- Prometheus - Metrics collection
- Tempo - Distributed tracing
- Loki - Log aggregation
- Docker - Containerization
- Kubernetes - Container orchestration
- Resilience4J - Circuit breaker implementation
- Java 17+
- Maven 3.8+
- Docker & Docker Compose
- Kubernetes (optional)
-
Clone the repository
git clone https://github.com/khan-sk-dev/cloud-native-services.git cd cloud-native-services -
Build all services
mvn clean install
-
Start with Docker Compose
docker-compose up -d
-
Verify services are running
docker-compose ps
# Build specific service
cd product-service
mvn clean package
docker build -t product-service:latest .
# Or build all services
./build-all.sh# Start all services
docker-compose up -d
# View logs
docker-compose logs -f [service-name]
# Stop all services
docker-compose down# Apply all Kubernetes manifests
kubectl apply -f k8s/
# Check deployment status
kubectl get pods -n cloud-native
# Port forward to access services
kubectl port-forward svc/api-gateway 8080:8080# Get all services
kubectl get svc
# Get service details
kubectl describe svc api-gateway- URL:
http://localhost:3000 - Username:
admin - Password:
admin
- URL:
http://localhost:9090 - Targets:
http://localhost:9090/targets
Access metrics endpoints:
# Service health checks
curl http://localhost:8081/actuator/health
# Prometheus metrics
curl http://localhost:8081/actuator/prometheus
# Circuit breaker status
curl http://localhost:8080/actuator/circuitbreakers# Product Service (via Gateway)
GET /api/products
POST /api/products
GET /api/products/{id}
PUT /api/products/{id}
DELETE /api/products/{id}
# Order Service (via Gateway)
GET /api/orders
POST /api/orders
GET /api/orders/{id}
PUT /api/orders/{id}
# Inventory Service (via Gateway)
GET /api/inventory/{productId}
POST /api/inventory# Create a product
curl -X POST http://localhost:8080/api/products \
-H "Content-Type: application/json" \
-d '{
"name": "Laptop",
"description": "High-performance laptop",
"price": 999.99
}'
# Get all products
curl http://localhost:8080/api/products
# Place an order
curl -X POST http://localhost:8080/api/orders \
-H "Content-Type: application/json" \
-d '{
"productId": 1,
"quantity": 2,
"customerEmail": "customer@example.com"
}'# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_NAME=productdb
DB_USER=root
DB_PASSWORD=password
# Kafka Configuration
KAFKA_BOOTSTRAP_SERVERS=localhost:9092
KAFKA_GROUP_ID=notification-service
# Service Discovery
EUREKA_SERVER_URL=http://localhost:8761/eurekaEach service has its own application.yml configuration:
server:
port: 8081
spring:
datasource:
url: jdbc:mysql://localhost:3306/productdb
username: ${DB_USER:root}
password: ${DB_PASSWORD:password}
kafka:
bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}
consumer:
group-id: ${KAFKA_GROUP_ID:product-service}
management:
endpoints:
web:
exposure:
include: health,info,prometheus,metrics# Run tests for all services
mvn test
# Run tests for specific service
cd product-service
mvn test# Run integration tests
mvn verify -P integration-tests# Using Apache Bench
ab -n 1000 -c 10 http://localhost:8080/api/products
# Using curl for stress testing
for i in {1..100}; do
curl -X POST http://localhost:8080/api/products \
-H "Content-Type: application/json" \
-d '{"name":"Product'$i'","price":99.99}' &
done-
Port conflicts
# Check if ports are in use netstat -tulpn | grep :8080 # Kill process using port kill -9 $(lsof -ti:8080)
-
Database connection issues
# Check database connectivity docker exec -it mysql-container mysql -u root -p
-
Service discovery problems
# Check Eureka dashboard curl http://localhost:8761/eureka/apps
# View application logs
docker logs -f product-service
# View all services logs
docker-compose logs -f# Optimize JVM parameters
export JAVA_OPTS="-Xms512m -Xmx1024m -XX:+UseG1GC"- Connection pooling configuration
- Database indexing strategies
- Query optimization
- Redis for distributed caching
- Application-level caching with Spring Cache
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Commit your changes
git commit -m 'Add some amazing feature' - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- Follow Google Java Style Guide
- Use meaningful commit messages
- Add tests for new features
- Update documentation
- Spring Boot team for the amazing framework
- Docker for containerization platform
- Kubernetes community for orchestration
- Grafana Labs for monitoring solutions
⭐ Star this repository if you find it helpful!
Made with ❤️ by Khan SK Dev
