Skip to content

rajadilipkolli/spring-boot-microservices-series-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Spring Boot Microservices Series V2

Open in Gitpod

A comprehensive microservices architecture showcase using modern cloud-native technologies

Building resilient, scalable, and observable distributed systems with Spring Boot ecosystem

Microservices Architecture


πŸ“– Table of Contents

🎯 Overview

This project demonstrates a complete microservices architecture built with Spring Boot, Spring Cloud, and modern cloud-native technologies. It serves as a practical guide for developers looking to understand and implement production-ready distributed systems.

✨ Key Features

🏒 Microservice Architecture

  • Decoupled services for different business domains
  • Independent deployment and scaling
  • Domain-driven design principles

🌱 Spring Boot & Spring Cloud

  • Service Registry (Eureka)
  • API Gateway (Spring Cloud Gateway)
  • Configuration Server
  • Circuit Breakers & Load Balancing

🐳 Containerization

  • Dockerized services
  • Docker Compose orchestration
  • Consistent development environments

πŸ“‘ Event-Driven Communication

  • Apache Kafka message streaming
  • Asynchronous service communication
  • Event sourcing patterns

πŸ“Š Comprehensive Observability

  • Prometheus metrics collection
  • Grafana dashboards
  • Distributed tracing with Micrometer
  • Centralized logging

πŸ—„οΈ Database Diversity

  • PostgreSQL
  • Liquibase schema management
  • Multiple changelog formats (XML, YAML, JSON)

πŸ” Service Discovery

  • Eureka service registry
  • Dynamic service registration
  • Health check monitoring

πŸ›‘οΈ Production Ready

  • Security with OAuth2/OIDC
  • Performance testing with Gatling
  • CI/CD with GitHub Actions

πŸ—οΈ Architecture

This project implements a microservices pattern where different functionalities are broken down into independent services. These services communicate asynchronously via Apache Kafka and are managed through Spring Cloud Gateway and Eureka Service Discovery.

Architecture Highlights:

  • 🌐 API Gateway as the single entry point
  • πŸ“‹ Service Registry for dynamic service discovery
  • βš™οΈ Configuration Server for centralized config management
  • πŸ“¨ Event-driven communication via Kafka
  • πŸ“Š Distributed monitoring and tracing

πŸ“¦ Services Overview

Service Port Description Tech Stack
🌐 API Gateway 8765 Single entry point, routing & load balancing Spring Cloud Gateway
πŸ“ Config Server 8888 Centralized configuration management Spring Cloud Config
🏒 Service Registry 8761 Service discovery with Eureka Spring Cloud Netflix
πŸ“š Catalog Service 18080 Product catalog management PostgreSQL + Liquibase (YAML)
πŸ“¦ Inventory Service 18181 Stock level management PostgreSQL + Liquibase (JSON)
πŸ›οΈ Order Service 18282 Order processing & orchestration PostgreSQL + Liquibase (XML)
πŸ’³ Payment Service 18085 Payment processing PostgreSQL + Liquibase (XML)
πŸ›’ Retail Store Web 8080 Customer-facing web application Thymeleaf + Alpine.js

πŸ”— Service Interactions

graph TB
    UI[πŸ›’ Retail Store WebApp] --> GW[🌐 API Gateway]
    GW --> CS[πŸ“š Catalog Service]
    GW --> IS[πŸ“¦ Inventory Service]
    GW --> OS[πŸ›οΈ Order Service]
    GW --> PS[πŸ’³ Payment Service]
    
    OS -.->|Events| Kafka[πŸ“‘ Kafka]
    PS -.->|Events| Kafka
    IS -.->|Events| Kafka
    
    SR[🏒 Service Registry] -.->|Discovery| GW
    SR -.->|Discovery| CS
    SR -.->|Discovery| IS
    SR -.->|Discovery| OS
    SR -.->|Discovery| PS
    
    CC[πŸ“ Config Server] -.->|Configuration| GW
    CC -.->|Configuration| CS
    CC -.->|Configuration| IS
    CC -.->|Configuration| OS
    CC -.->|Configuration| PS
    
    style UI fill:#e1f5fe
    style GW fill:#f3e5f5
    style Kafka fill:#fff3e0
    style SR fill:#e8f5e8
    style CC fill:#fce4ec
Loading

πŸ”§ Tech Stack

πŸ–₯️ Core Technologies

Languages & Frameworks

πŸ“‘ Communication & Messaging

Message Brokers & Streaming

πŸ—„οΈ Data Storage & Management

Databases

Database Tools

🐳 DevOps & Deployment

Containerization & CI/CD

πŸ“Š Monitoring & Observability

Metrics & Tracing

Logging

πŸ§ͺ Testing

Testing Tools

  • JUnit JUnit 5
  • Gatling Gatling (Performance Testing)
  • Testcontainers Testcontainers

πŸ“‹ For complete tech stack details, see techstack.md

πŸš€ Quick Start

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

Tool Version Purpose
β˜• Java 21+ Runtime environment
πŸ“¦ Maven 3.9.x+ Build tool
🐳 Docker Latest Containerization
πŸ”§ Docker Compose Latest Orchestration
πŸ“š Git Latest Version control

πŸ’‘ Tip: Ensure JAVA_HOME environment variable is properly set

πŸ”¨ Build the Project

  1. Clone the repository:

    git clone https://github.com/rajadilipkolli/spring-boot-microservices-series-v2.git
    cd spring-boot-microservices-series-v2
  2. Build all modules:

    🐧 Linux/macOS:

    ./mvnw clean install

    πŸͺŸ Windows:

    .\mvnw.cmd clean install

πŸš€ Running the Application

Choose one of the following deployment options:

Option 1: Core Services Only

Perfect for development and basic functionality testing:

docker-compose -f deployment/docker-compose.yml up -d --remove-orphans

Option 2: Full Stack with Monitoring

Includes Prometheus, Grafana, and other observability tools:

docker-compose -f deployment/docker-compose-tools.yml up -d --remove-orphans

Option 3: Using Helper Scripts

🐧 Linux/macOS:

bash run.sh

πŸͺŸ Windows:

.\start-services.ps1

πŸ›‘ Stopping Services

# Stop core services
docker-compose -f deployment/docker-compose.yml down

# Stop services with monitoring tools
docker-compose -f deployment/docker-compose-tools.yml down

βœ… Verify Installation

Once all services are running, verify the setup:

πŸŽ›οΈ Service Discovery & API Access

πŸ” Service Registry (Eureka)

Monitor all registered microservices and their health status:

πŸ“š API Gateway & Documentation

Access all microservice APIs through a unified interface:

Swagger Documentation

πŸ’‘ Pro Tip: Use the dropdown menu in Swagger UI to switch between different service APIs

πŸ“Š Observability

πŸ“ˆ Metrics & Monitoring with Prometheus & Grafana

πŸ” Prometheus

  • URL: http://localhost:9090
  • Purpose: Metrics collection and alerting
  • Features: Custom queries, alert rules, service discovery

πŸ“Š Grafana

  • URL: http://localhost:3000
  • Credentials: admin/admin
  • Features: Beautiful dashboards, alerting, data visualization

🚨 Alertmanager

  • URL: http://localhost:9093
  • Purpose: Alert routing and management
  • Features: Email, Slack, webhook notifications

πŸ“‹ Key Metrics Monitored:

  • ⚑ Response times & throughput
  • πŸ’Ύ Memory & CPU usage
  • πŸ”„ Service health & availability
  • πŸ“Š Business metrics & KPIs

πŸ” Distributed Tracing

Zipkin Integration

  • URL: http://localhost:9411/zipkin/
  • Features: Request flow visualization, latency analysis, dependency mapping
  • Integration: Micrometer Tracing with Spring Boot

Zipkin Tracing

πŸ“Š Alerting Architecture

---
title: 🚨 Monitoring & Alerting Flow
---
flowchart TD
    subgraph "πŸ“Š Microservices"
        MS1[πŸ“š Catalog Service]
        MS2[πŸ“¦ Inventory Service]
        MS3[πŸ›οΈ Order Service]
        MS4[πŸ’³ Payment Service]
    end

    PROM[πŸ” Prometheus Server]
    AM[🚨 AlertManager]
    GRAF[πŸ“Š Grafana]
    RULES[πŸ“‹ Alert Rules]
    
    MS1 --> PROM
    MS2 --> PROM
    MS3 --> PROM
    MS4 --> PROM
    
    PROM --> RULES
    RULES --> AM
    AM --> |πŸ“§ Email| EMAIL[πŸ“§ Notifications]
    AM --> |πŸ’¬ Slack| SLACK[πŸ’¬ Chat Alerts]
    
    PROM --> GRAF
    
    style PROM fill:#ff6b6b
    style AM fill:#4ecdc4
    style GRAF fill:#45b7d1
    style RULES fill:#f9ca24
Loading

πŸ—ƒοΈ Database Management

πŸ“Š Liquibase Schema Management

This project demonstrates flexible database schema management using Liquibase with various changelog formats:

🏷️ Format πŸ“ Service Examples πŸ“ Use Case
XML order-service, payment-service Complex migrations, detailed documentation
YAML catalog-service Human-readable, simple structure
JSON inventory-service API-friendly, structured data
SQL Custom implementations Direct SQL control, legacy migrations

πŸ“‚ Changelog Location

src/main/resources/db/changelog/
β”œβ”€β”€ db.changelog-master.xml     # Master changelog file
β”œβ”€β”€ migrations/
β”‚   β”œβ”€β”€ 001-initial-schema.xml
β”‚   β”œβ”€β”€ 002-add-indexes.yaml
β”‚   └── 003-seed-data.json

πŸ—„οΈ Database Technologies

🐘 PostgreSQL Services

  • πŸ“š Catalog Service
  • πŸ“¦ Inventory Service
  • πŸ›οΈ Order Service
  • πŸ’³ Payment Service

Features: ACID compliance, complex queries, relational integrity

πŸ’‘ Best Practice: Each service manages its own database schema independently, following the database-per-service pattern

πŸ’‘ Development Tips

🐳 Essential Docker Commands

🧹 Cleanup Commands
# πŸ—‘οΈ Clean up entire Docker system (nuclear option)
docker system prune -a -f --volumes

# πŸ“¦ Remove unused volumes only
docker volume prune -f

# πŸ” List all running containers
docker ps

# πŸ“‹ List all containers (including stopped)
docker ps -a
πŸ“‹ Logging Commands
# πŸ“Š View logs for all services (with monitoring tools)
docker-compose -f deployment/docker-compose-tools.yml logs -f

# 🎯 View logs for specific service
docker-compose -f deployment/docker-compose.yml logs -f order-service

# πŸ“œ Follow logs from last 100 lines
docker-compose -f deployment/docker-compose-tools.yml logs --tail=100 -f

# πŸ” Search logs for specific patterns
docker-compose logs | grep ERROR

🚫 Kill Processes by Port

πŸͺŸ Windows (PowerShell/CMD)
# πŸ” Find process using port 18080
netstat -ano | findstr :18080

# ⚑ Kill process by PID
taskkill /PID <PID_FROM_ABOVE> /F

# 🎯 One-liner to kill process on port
$process = Get-NetTCPConnection -LocalPort 18080 -ErrorAction SilentlyContinue
if ($process) { Stop-Process -Id $process.OwningProcess -Force }
🐧 Linux/macOS (Terminal)
# πŸ” Find process using port 18080
sudo lsof -i :18080

# ⚑ Kill process by PID
kill -9 <PID_FROM_ABOVE>

# 🎯 One-liner to kill process on port
sudo kill -9 $(sudo lsof -t -i:18080)

# πŸ”₯ Alternative using fuser
sudo fuser -k 18080/tcp

⚠️ Important Notes & Best Practices

πŸ”„ Spring Boot 3.x Migration Notes
  • πŸ“¦ Jakarta EE Namespace: Migration from javax.* to jakarta.*
  • πŸ“Š Observability: Spring Cloud Sleuth β†’ Micrometer Tracing
  • πŸ”§ Configuration: Updated property names and patterns
  • πŸ›‘οΈ Security: Enhanced OAuth2/OIDC integration
πŸ§ͺ Testing Best Practices
// πŸ’° BigDecimal testing with precision handling
import static org.hamcrest.Matchers.closeTo;

// ❌ Don't do this:
// .andExpected(jsonPath("$.totalPrice").value(100.00))

// βœ… Do this instead:
.andExpect(jsonPath("$.totalPrice").value(closeTo(new BigDecimal("100.00"), new BigDecimal("0.01"))))
πŸ—οΈ Architecture Considerations
  • πŸ”„ Transaction Management: Use @Transactional directly on jOOQ repository methods
  • πŸ“Š Event Sourcing: Kafka integration for reliable message delivery
  • πŸš€ Native Images: Some services may need additional GraalVM configuration
  • πŸ” Service Discovery: Health checks are crucial for proper load balancing

🎯 Performance Testing

# πŸš€ Run Gatling performance tests
cd gatling-tests

# πŸ“Š Basic performance test
./mvnw gatling:test

# πŸ”₯ Stress test with custom parameters
./mvnw gatling:test -P stress -DmaxUsers=100 -DrampDurationMinutes=5

🀝 Contributing

We welcome contributions from the community! Here's how you can help:

πŸš€ How to Contribute

  1. 🍴 Fork the repository
  2. 🌟 Create a feature branch: git checkout -b feature/amazing-feature
  3. πŸ’» Make your changes with clear, tested code
  4. πŸ“ Commit your changes: git commit -m 'Add amazing feature'
  5. πŸ“€ Push to the branch: git push origin feature/amazing-feature
  6. πŸ”„ Open a Pull Request

πŸ“‹ Contribution Guidelines

  • πŸ“– Documentation: Update documentation for any new features
  • πŸ§ͺ Testing: Add tests for new functionality
  • 🎨 Code Style: Follow existing code conventions
  • πŸ’¬ Discussion: Open an issue first for significant changes

πŸ€— Community Standards

Please read our Code of Conduct to understand our community standards and expectations.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License - Feel free to use, modify, and distribute! πŸŽ‰

πŸ™ Acknowledgements & References

πŸ“š Inspiration & Resources

🎯 Special Thanks

  • πŸ—οΈ Architecture Patterns: Following domain-driven design principles
  • πŸ”§ DevOps Practices: Docker, monitoring, and observability best practices
  • πŸ‘₯ Community: All contributors and users who make this project better

⭐ If this project helped you, please give it a star! ⭐

Made with ❀️ by the Spring Boot Microservices Community

πŸ› Report Bug β€’ ✨ Request Feature β€’ πŸ’¬ Discussions

Releases

No releases published

Packages

No packages published