How pallava/spring-boot-with-microservice works
Project Type and Purpose
• This repository is a “Spring-boot-with-microservice” demo showcasing a set of backend microservices built on Spring Cloud.
• Key modules:
• cloud-config – a centralized configuration server
• application-service-registry – a Eureka service registry
• api-gateway – a Zuul/Spring Cloud Gateway entry point with routing and fallback
• department – a simple Department microservice (REST + JPA)
• user-service – a User microservice that uses Feign to call Department
File Structure
• Top-level folders correspond to each microservice. Each follows the standard Maven layout: src/main/java, src/main/resources, Dockerfile, pom.xml.
• Presence of bootstrap.yml and application.yml in each service indicates Spring Cloud configuration.
• api-gateway contains a CustomFilter and FallBackController, pointing to a gateway pattern with circuit-breaker fallback.
• user-service has a feignclients package and DTO for Department—showing inter-service communication.
README for Insights
• Very brief (“Simple demo with Spring boot and Microservice”).
Main Components & Their Roles
a. Client (e.g., Postman or UI)
– Initiates all HTTP requests.
b. API Gateway
– Single entry point. Routes incoming calls to the appropriate microservice.
– Implements filters (authentication, logging) and circuit-breaker fallbacks.
c. Service Registry (Eureka)
– Keeps track of service instances and their health.
– Gateway and microservices register themselves here.
d. Config Server
– Serves centralized configuration to all microservices at startup.
e. Microservices
– department: CRUD REST API backed by a relational database (via Spring Data JPA).
– user-service: User REST API that, when requested, calls department service via Feign load-balanced client.
f. Databases (one per microservice)
– department-db and user-db (could be separate instances or schemas).
Relationships & Data Flows
1. Client → API Gateway: all requests go through gateway.
2. API Gateway → Eureka: on startup, gateway queries Eureka for route mappings.
3. API Gateway → Config Server: gateway fetches its config.
4. API Gateway → department / user-service: routes based on path (/department/, /user/).
5. user-service → Eureka: registers itself; Eureka returns department instances for Feign.
6. user-service → Config Server: fetches config.
7. user-service → department-service: inter-service call via Feign + Ribbon for load balancing.
8. Each service → its own Database: reads/writes entities.
Architectural Patterns & Principles
• Microservices: each service is independently deployable, with its own codebase and data store.
• Service Discovery: Eureka-based registration and lookup.
• API Gateway: single entry point, encapsulating cross-cutting concerns (security, rate-limiting, circuit breakers).
• Externalized Configuration: Spring Cloud Config for dynamic, centralized configuration.
• Client-side Load Balancing: Netflix Ribbon (used implicitly by Feign).
• Circuit Breaker / Fallback: Hystrix-style fallback implemented in API gateway.
Technologies & Frameworks
• Spring Boot, Spring Cloud (Config, Netflix Eureka, Netflix Zuul/Gateway, Netflix Feign, Ribbon, Hystrix)
• Maven for build
• Dockerfiles for containerization
• Spring Data JPA (for persistence)
Step-by-Step Creation
4. “Eureka Service Registry” in the center/top; connect Gateway and services bi-directionally.