Scalable β’ Resilient β’ Observable β’ Event-Driven
- π― Overview
- β¨ Key Features
- ποΈ Architecture
- π οΈ Tech Stack
- π Quick Start
- π Service Details
- π§ Configuration
- π Monitoring & Observability
- π§ͺ Testing
- π€ Contributing
- π License
This project demonstrates a real-world microservices architecture for supply chain management, showcasing best practices in distributed systems design. Built with Spring Cloud ecosystem, it provides a robust foundation for scalable enterprise applications.
- π Event-Driven Architecture with Apache Kafka
- π‘οΈ Fault Tolerance with Circuit Breakers
- π Full Observability with distributed tracing
- πͺ API Gateway as single entry point
- π Centralized Logging with ELK Stack
- π Secure Authentication & Authorization
- βοΈ Externalized Configuration management
|
|
graph TB
Client[π€ Client] --> Gateway[πͺ API Gateway]
Gateway --> Auth[π Auth Server]
Gateway --> Product[ποΈ Product Service]
Gateway --> Order[π¦ Order Service]
Order -->|Sync Call| Inventory[π Inventory Service]
Order -->|Async Event| Kafka[π Kafka]
Kafka --> Notification[π Notification Service]
Product --> MongoDB[(π MongoDB)]
Order --> MySQL1[(ποΈ MySQL)]
Inventory --> MySQL2[(ποΈ MySQL)]
subgraph "π οΈ Infrastructure"
Eureka[π Eureka Server]
Config[βοΈ Config Server]
Zipkin[π Zipkin]
ELK[π ELK Stack]
end
subgraph "π§ External Config"
GitHub[π GitHub]
Vault[π HashiCorp Vault]
end
Config --> GitHub
Config --> Vault
style Client fill:#e1f5fe
style Gateway fill:#f3e5f5
style Kafka fill:#fff3e0
style ELK fill:#e8f5e8
Each microservice follows a clean, layered architecture:
βββββββββββββββββββββββββββββββββββββββ
β π API Layer β
β (Controllers & DTOs) β
βββββββββββββββββββββββββββββββββββββββ€
β πΌ Business Layer β
β (Services & Domain) β
βββββββββββββββββββββββββββββββββββββββ€
β ποΈ Persistence Layer β
β (Repositories & Entities) β
βββββββββββββββββββββββββββββββββββββββ€
β π Integration Layer β
β (Message Queues & External) β
βββββββββββββββββββββββββββββββββββββββ
| Requirement | Version | Purpose |
|---|---|---|
| β Java JDK | 17+ | Runtime environment |
| π³ Docker | 20.10+ | Containerization |
| π³ Docker Compose | 2.0+ | Multi-container orchestration |
| π¨ Maven | 3.8+ | Build automation |
| πΎ Available RAM | 8GB+ | Running all services |
# Clone the repository
git clone https://github.com/your-username/spring-boot-microservices.git
cd spring-boot-microservices
# Start the entire stack
make up
# OR
docker-compose up -d && ./scripts/start-services.shClick to expand manual setup instructions
# Start backing services
docker-compose up -d mongodb mysql kafka zookeeper elasticsearch kibana zipkin
# Wait for services to be ready
./scripts/wait-for-services.sh# 1. Configuration Server
cd config-server && mvn spring-boot:run &
# 2. Discovery Server
cd discovery-server && mvn spring-boot:run &
# 3. Gateway
cd api-gateway && mvn spring-boot:run &
# 4. Business Services
cd product-service && mvn spring-boot:run &
cd inventory-service && mvn spring-boot:run &
cd order-service && mvn spring-boot:run &
cd notification-service && mvn spring-boot:run &After startup, check these endpoints:
| Service | URL | Status |
|---|---|---|
| πͺ API Gateway | http://localhost:8080 | |
| π Eureka Dashboard | http://localhost:8761 | |
| π Zipkin Tracing | http://localhost:9411 | |
| π Kibana Logs | http://localhost:5601 |
ποΈ Product Service
Purpose: Manages product catalog and inventory display
Tech Stack: Spring Boot + MongoDB + Spring Data MongoDB
Key Features:
- β Product CRUD operations
- β Category management
- β Search and filtering
- β Product recommendations
API Endpoints:
GET /api/products # List all products
GET /api/products/{id} # Get product details
POST /api/products # Create new product
PUT /api/products/{id} # Update product
DELETE /api/products/{id} # Delete product
GET /api/products/search # Search productsπ¦ Order Service
Purpose: Handles complete order lifecycle management
Tech Stack: Spring Boot + MySQL + JPA + Kafka Producer
Key Features:
- β Order creation and management
- β Inventory validation (sync call)
- β Payment processing integration
- β Order status tracking
- β Event publishing for notifications
API Endpoints:
POST /api/orders # Create new order
GET /api/orders/{id} # Get order details
GET /api/orders/user/{id} # Get user orders
PUT /api/orders/{id}/status # Update order status
DELETE /api/orders/{id} # Cancel orderπ Inventory Service
Purpose: Real-time inventory tracking and management
Tech Stack: Spring Boot + MySQL + JPA + Redis Cache
Key Features:
- β Stock level management
- β Real-time availability checks
- β Low stock alerts
- β Inventory reservations
- β Audit trail for stock changes
API Endpoints:
GET /api/inventory/{productId} # Check stock
POST /api/inventory/reserve # Reserve stock
POST /api/inventory/release # Release reservation
PUT /api/inventory/{productId} # Update stock
GET /api/inventory/low-stock # Get low stock itemsπ Notification Service
Purpose: Multi-channel customer notifications
Tech Stack: Spring Boot + Kafka Consumer + Email/SMS APIs
Key Features:
- β Email notifications
- β SMS alerts
- β Push notifications
- β Notification templates
- β Delivery tracking
Supported Events:
- π§ Order confirmation
- π± Shipping updates
β οΈ Low stock alerts- π Promotional offers
| Profile | Purpose | Config Source |
|---|---|---|
local |
Development | Local files |
dev |
Development server | Config Server + GitHub |
staging |
Pre-production | Config Server + Vault |
prod |
Production | Config Server + Vault + Encryption |
config-repo/
βββ application.yml # Global configuration
βββ application-{profile}.yml # Profile-specific config
βββ api-gateway.yml # Gateway routing rules
βββ product-service.yml # Product service config
βββ order-service.yml # Order service config
βββ inventory-service.yml # Inventory service config
# Example security configuration
security:
oauth2:
client:
registration:
gateway:
client-id: ${OAUTH2_CLIENT_ID}
client-secret: ${OAUTH2_CLIENT_SECRET}
scope: read,write
resource-server:
jwt:
issuer-uri: ${JWT_ISSUER_URI}Zipkin Integration provides end-to-end request tracing:
- π Request flow visualization
- β±οΈ Latency analysis
- π Error detection
- π Performance bottleneck identification
Prometheus + Grafana stack for metrics:
- π JVM metrics
- π HTTP request metrics
- πΎ Database connection pools
- π Kafka consumer lag
- πΏ Custom business metrics
ELK Stack for log aggregation:
{
"timestamp": "2024-01-15T10:30:00Z",
"service": "order-service",
"traceId": "abc123def456",
"spanId": "789ghi012jkl",
"level": "INFO",
"message": "Order created successfully",
"userId": "user-123",
"orderId": "order-456"
}Each service exposes comprehensive health endpoints:
GET /actuator/health # Overall health
GET /actuator/info # Service information
GET /actuator/metrics # Prometheus metrics
GET /actuator/env # Environment details|
π¬ Unit Tests
|
π Integration Tests
|
π E2E Tests
|
# Run all tests
mvn clean test
# Run specific test categories
mvn test -Dgroups="unit"
mvn test -Dgroups="integration"
mvn test -Dgroups="e2e"
# Generate coverage report
mvn jacoco:report| Service | Unit Tests | Integration Tests | Coverage |
|---|---|---|---|
| Product Service | β 45 tests | β 12 tests | 92% |
| Order Service | β 38 tests | β 15 tests | 88% |
| Inventory Service | β 32 tests | β 10 tests | 90% |
| Notification Service | β 28 tests | β 8 tests | 85% |
spring-boot-microservices/
βββ π services/
β βββ πͺ api-gateway/ # Spring Cloud Gateway
β βββ π auth-server/ # OAuth2 Authorization Server
β βββ βοΈ config-server/ # Spring Cloud Config
β βββ π discovery-server/ # Eureka Discovery Server
β βββ ποΈ product-service/ # Product management
β βββ π¦ order-service/ # Order processing
β βββ π inventory-service/ # Inventory management
β βββ π notification-service/ # Notification handling
βββ π infrastructure/
β βββ π³ docker/ # Docker configurations
β βββ βΈοΈ kubernetes/ # K8s manifests
β βββ π monitoring/ # Grafana dashboards
βββ π config-repo/ # External configuration
βββ π scripts/ # Automation scripts
βββ π docs/ # Documentation
βββ π³ docker-compose.yml # Local development stack
βββ π Makefile # Build automation
βββ π README.md # This file
We welcome contributions! Please see our Contributing Guide for details.
- π΄ Fork the repository
- πΏ Create a feature branch:
git checkout -b feature/amazing-feature - π« Make your changes with tests
- β
Ensure all tests pass:
mvn clean verify - π Commit your changes:
git commit -m 'feat: add amazing feature' - π Push to the branch:
git push origin feature/amazing-feature - π¬ Open a Pull Request
- Follow Conventional Commits
- Maintain test coverage above 85%
- Update documentation for new features
- Follow the existing code style
Found a bug? Please open an issue with:
- π Description: What went wrong?
- π Steps to reproduce: How can we recreate it?
- π― Expected behavior: What should happen?
- π» Environment: OS, Java version, etc.
Special thanks to:
- π Spring Team for the amazing Spring Cloud ecosystem
- π Netflix OSS for pioneering microservices patterns
- π³ Docker Community for containerization standards
- π₯ All Contributors who make this project better