A comprehensive microservices architecture with API Gateway, service discovery, authentication, monitoring, and observability.
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Load Balancer ββββββ API Gateway ββββββ Discovery Serverβ
β (External) β β (Port 8080) β β (Port 8761) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
β
βββββββββββββΌβββββββββββββ
β β β
βββββββββΌβββββ ββββββΌββββββββ ββββΌβββββββββββββ
βAuth Serviceβ βUser Serviceβ βProduct Serviceβ
β(Dynamic) β β(Dynamic) β β(Dynamic) β
ββββββββββββββ ββββββββββββββ βββββββββββββββββ
β
β
βββββββββββββΌββββββββββββ
β Monitoring Stack β
β Prometheus | Grafana β
β Zipkin | ELK β
βββββββββββββββββββββββββ
-
Discovery Server (Port 8761 - Fixed)
- Eureka server for service registration and discovery
- Service health monitoring
- Load balancing coordination
-
API Gateway (Port 8080 - Fixed)
- Single entry point for all client requests
- JWT authentication validation
- Rate limiting and throttling
- Request routing and load balancing
- CORS handling
-
Auth Service (Dynamic Port - Discovered via Eureka)
- JWT token generation and validation
- User authentication
- Security endpoints
- Accessed via Gateway:
http://localhost:8080/auth-service
-
User Service (Dynamic Port - Discovered via Eureka)
- User management CRUD operations
- User profile management
- Secured with JWT
- Accessed via Gateway:
http://localhost:8080/user-service
-
Product Service (Dynamic Port - Discovered via Eureka)
- Product catalog management
- Product CRUD operations
- Category management
- Accessed via Gateway:
http://localhost:8080/product-service
- Prometheus (Port 9090) - Metrics collection
- Grafana (Port 3000) - Visualization dashboards
- Zipkin (Port 9411) - Distributed tracing
- ELK Stack - Centralized logging
- Elasticsearch (Port 9200)
- Logstash (Port 5044)
- Kibana (Port 5601)
- Framework: Spring Boot 3.2.5
- Language: Java 22
- Cloud: Spring Cloud 2023.0.1
- Security: JWT with JJWT 0.9.1
- Database: H2 (Development)
- Monitoring: Micrometer + Prometheus
- Tracing: Zipkin with Brave
- API Gateway: Spring Cloud Gateway
- Discovery: Netflix Eureka
- Build Tool: Maven
- Containerization: Docker & Docker Compose
- Java 22 or higher
- Maven 3.6 or higher
- Docker and Docker Compose (for monitoring)
- curl (for testing)
# Start monitoring infrastructure
./start-monitoring.sh
# Wait for services to be ready (2-3 minutes)
# Check status at http://localhost:3000 (Grafana)# Start all microservices in correct order
./start-services.sh
# This will:
# 1. Start Discovery Server (8761)
# 2. Start API Gateway (8080)
# 3. Start Auth Service (8081)
# 4. Start User Service (8082)
# 5. Start Product Service (8083)# Run comprehensive API tests
./test-apis.sh
# This will test:
# - Service health checks
# - Authentication flow
# - User CRUD operations
# - Product CRUD operations
# - Rate limiting
# - Monitoring endpoints# Stop all microservices
./stop-services.sh
# Stop monitoring stack
docker-compose -f docker-compose-monitoring.yml down# 1. Discovery Server (must be first)
cd discovery-server && mvn spring-boot:run &
# 2. API Gateway (wait for discovery server)
cd api-gateway && mvn spring-boot:run &
# 3. Auth Service
cd auth-service && mvn spring-boot:run &
# 4. User Service
cd user-service && mvn spring-boot:run &
# 5. Product Service
cd product-service && mvn spring-boot:run &# Login to get JWT token
curl -X POST http://localhost:8080/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"password"}'
# Response: {"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}# Create user (requires JWT token)
curl -X POST http://localhost:8080/users \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"username":"john","email":"[email protected]","firstName":"John","lastName":"Doe"}'
# Get all users
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:8080/users
# Get user by ID
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:8080/users/1# Create product (requires JWT token)
curl -X POST http://localhost:8080/products \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Laptop","description":"Gaming laptop","price":999.99,"category":"Electronics"}'
# Get all products
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:8080/products
# Get product by ID
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:8080/products/1- Discovery Server: http://localhost:8761
- API Gateway: http://localhost:8080
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (admin/admin)
- Zipkin: http://localhost:9411
- Kibana: http://localhost:5601
# Gateway metrics
curl http://localhost:8080/actuator/metrics
curl http://localhost:8080/actuator/prometheus
# Service metrics
curl http://localhost:8082/actuator/health
curl http://localhost:8083/actuator/health- JVM Metrics - Memory, CPU, GC
- Spring Boot Metrics - HTTP requests, database connections
- Gateway Metrics - Route-specific metrics
- Business Metrics - User/Product operations
- All API endpoints (except auth) require JWT tokens
- Tokens include user information and expiration
- Gateway validates tokens before forwarding requests
- Configured per-user rate limiting
- Default: 10 requests per minute per user
- Returns 429 Too Many Requests when exceeded
- Configured for cross-origin requests
- Allows common HTTP methods
- Configurable origins
MicroservicesApiGateway/
βββ discovery-server/ # Eureka service registry
βββ api-gateway/ # Spring Cloud Gateway
βββ auth-service/ # JWT authentication
βββ user-service/ # User management
βββ product-service/ # Product management
βββ monitoring/ # Monitoring configuration
β βββ prometheus.yml
β βββ grafana/
βββ docker-compose-monitoring.yml
βββ start-services.sh # Start all services
βββ stop-services.sh # Stop all services
βββ service-manager.sh # Individual service management
βββ test-apis.sh # API functionality testing
βββ test-load-balancing.sh # Load balancing tests
βββ setup-load-test.sh # Load test environment setup
βββ cleanup-load-test.sh # Load test cleanup
βββ start-monitoring.sh # Start monitoring stack
βββ test-apis.sh # API testing script
βββ MONITORING.md # Monitoring documentation
βββ README.md # This file
# Service ports
DISCOVERY_PORT=8761
GATEWAY_PORT=8080
AUTH_PORT=8081
USER_PORT=8082
PRODUCT_PORT=8083
# JWT Configuration
JWT_SECRET=your-secret-key
JWT_EXPIRATION=86400000
# Database
DB_URL=jdbc:h2:mem:testdb
DB_USERNAME=sa
DB_PASSWORD=development- H2 database, debug loggingproduction- External database, optimized loggingdocker- Container-specific configuration
-
Port Already in Use
# Find process using port lsof -i :8080 # Kill process kill -9 <PID>
-
Services Not Registering
- Ensure Discovery Server is running first
- Check application.yml for correct Eureka URL
- Verify network connectivity
-
Authentication Issues
- Check JWT token format
- Verify token hasn't expired
- Ensure correct Authorization header format
-
Monitoring Not Working
- Start monitoring stack first
- Check Docker containers are running
- Verify port accessibility
# Service logs (when using start-services.sh)
tail -f logs/discovery-server.log
tail -f logs/api-gateway.log
tail -f logs/auth-service.log
tail -f logs/user-service.log
tail -f logs/product-service.log
# Direct Maven logs
cd service-directory && mvn spring-boot:run- Gateway uses Spring Cloud LoadBalancer
- Round-robin distribution by default
- Health check-based routing
- Support for multiple service instances
# Setup load test environment
./setup-load-test.sh
# Run comprehensive load balancing tests
./test-load-balancing.sh
# Clean up after testing
./cleanup-load-test.shSee LOAD_BALANCING_TESTS.md for detailed testing guide.
- Service discovery information cached
- JWT tokens validated with caching
- Database queries optimized
- Services are stateless (except auth tokens)
- Can run multiple instances behind load balancer
- Database should be externalized for production
- Dynamic port allocation prevents port conflicts
- Make Changes: Edit service code
- Build:
mvn clean compilein service directory - Test: Run individual service or full test suite
- Monitor: Check Grafana dashboards for metrics
- Deploy: Restart specific service or full stack
# Build all services
for service in discovery-server api-gateway auth-service user-service product-service; do
cd $service
mvn clean package
cd ..
done
# Create Docker images (Dockerfiles needed)
# Deploy with Docker Compose or Kubernetes# Example Kubernetes resources needed:
# - ConfigMaps for application.yml
# - Secrets for JWT keys
# - Services for inter-service communication
# - Ingress for external access
# - HorizontalPodAutoscaler for scaling- Monitoring Setup - Detailed monitoring configuration
- Service READMEs - Individual service documentation
- API Documentation - Detailed API specifications (create as needed)
- Fork the repository
- Create feature branch
- Make changes with tests
- Update documentation
- Submit pull request
This project is licensed under the MIT License - see the LICENSE file for details.