This project demonstrates the implementation of a resilient microservices architecture using Spring Boot, Spring Cloud, and Resilience4j.
- Service Discovery: Automatic service registration and discovery using Netflix Eureka.
- Circuit Breaker: Fault isolation and prevention of cascading failures using Resilience4j.
- Retry: Automatic retries of failed requests.
- Bulkhead: Limiting the number of concurrent calls to prevent overload.
- Rate Limiting: Limiting the number of API requests using Spring Cloud Gateway and Redis.
- Timeouts & Fallbacks: Configuration of HTTP request timeouts and implementation of fallback scenarios.
- Monitoring & Observability: Metric collection using Micrometer and Prometheus, visualization in Grafana, and distributed tracing with Zipkin.
discovery-service: Eureka Server for service registration and discovery.order-service: A service for creating orders. It demonstrates the application of Circuit Breaker, Retry, Bulkhead, and Fallback patterns when communicating withinventory-service.inventory-service: A service for managing inventory.gateway-service: An API gateway built with Spring Cloud Gateway that routes requests and applies Rate Limiting.
- Java 17+
- Maven
- Docker and Docker Compose
-
Start the monitoring infrastructure and Redis: In the root directory of the project, run the command:
docker-compose up -d
This command will start Prometheus, Grafana, Zipkin, and Redis in Docker containers.
-
Start the microservices: Start each of the Spring Boot applications in the following order:
discovery-serviceinventory-serviceorder-servicegateway-service
You can do this from your IDE (e.g., IntelliJ IDEA) or using Maven:
# For each service mvn spring-boot:run
- Eureka Dashboard: http://localhost:8761
- API Gateway: http://localhost:8080
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (login/password:
admin/admin) - Zipkin: http://localhost:9411
-
Creating an order (successful scenario): Send a GET request to the gateway:
curl http://localhost:8080/api/orders
You should receive a response from
inventory-service. -
Testing Circuit Breaker and Fallback:
- Stop the
inventory-service. - Send several requests to
http://localhost:8080/api/orders. - After a few failed attempts, the Circuit Breaker will transition to the "Open" state, and
order-servicewill start returning cached data from the fallback method:{"data":"cached-data","fromCache":true}.
- Stop the
-
Testing Rate Limiter: Try sending a large number of requests in a short period. For example, using the
ab(Apache Benchmark) utility:ab -n 50 -c 10 http://localhost:8080/api/orders/
Some of the requests will be rejected with an HTTP status of
429 Too Many Requests. -
Monitoring:
- Open Grafana and create a dashboard for Resilience4j metrics (e.g.,
resilience4j_circuitbreaker_state). - Open Zipkin to trace distributed requests between services.
- Open Grafana and create a dashboard for Resilience4j metrics (e.g.,