How kartikchaudharygit/microservices-new works
Project Type and Purpose
• This is a Spring Boot microservices reference implementation. It demonstrates API Gateway, service discovery (Eureka), loosely coupled RESTful services, event-driven communication (Apache Kafka), and observability (Prometheus + Grafana).
File Structure Analysis
• Top-level modules (Maven multimodule project):
• api-gateway (Spring Cloud Gateway/Zuul)
• discovery-server (Eureka)
• inventory-service, order-service, product-service, notification-service (business microservices)
• prometheus (Prometheus config)
• Grafana_Dashboard.json
• docker-compose.yml (service orchestration)
• Each microservice follows standard packages: controller, service, repository, model, dto, config.
• Common patterns: OpenAPIConfig (Swagger), WebClientConfig (inter-service REST), KafkaConsumer (in notification), application.properties for external endpoints, banner, tests.
README Insights
• Core technologies: Spring Boot, Spring Cloud (Gateway, Eureka), Apache Kafka, Swagger/OpenAPI, Spring Boot Actuator, Prometheus, Grafana.
• Architectural patterns:
• API Gateway for routing and cross-cutting concerns
• Eureka for dynamic service discovery and client-side load balancing
• Event-driven microservices via Kafka (publish/subscribe)
• Separate databases per service implied by repository layers
• Observability via Actuator → Prometheus → Grafana
Main Components
a. External Clients (e.g., Web UI, Mobile App)
b. API Gateway
c. Eureka Discovery Server
d. Microservices (Inventory, Order, Product, Notification)
e. Message Broker (Kafka Cluster)
f. Databases (one per microservice)
g. Monitoring Stack (Spring Actuator endpoints, Prometheus, Grafana)
h. Orchestration (Docker Compose network)
Relationships & Interactions
• Clients → API Gateway: all HTTP traffic enters here.
• API Gateway ↔ Eureka: at startup and for routing lookup.
• API Gateway → Target Microservices: dynamic routing via service IDs registered in Eureka.
• Order Service → Inventory Service (“check stock”) via synchronous WebClient call.
• Order Service publishes OrderPlacedEvent → Kafka topic.
• Notification Service consumes OrderPlacedEvent from Kafka and sends notifications.
• Each microservice persists state in its own database (JPA repository).
• Spring Boot Actuator on each service exposes /actuator/prometheus metrics.
• Prometheus scrapes those endpoints.
• Grafana visualizes metrics via Prometheus data source.
Architectural Patterns & Principles
• Loose coupling: each service is autonomous, communicates over HTTP or Kafka.
• Single Responsibility: each microservice owns one business domain.
• Service Discovery: Eureka eliminates hard-coded service locations.
• API Composition: API Gateway centralizes routing, security, rate limiting, etc.
• Event-Driven: Kafka decouples producers and consumers for async processing.
• Observability: metrics, logs, dashboards ensure runtime visibility.