Skip to content

StackThrower/Resilient-Microservices-Architecture

Repository files navigation

Resilient Microservices Architecture

This project demonstrates the implementation of a resilient microservices architecture using Spring Boot, Spring Cloud, and Resilience4j.

Features

  • 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.

Modules

  • 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 with inventory-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.

How to Run

Prerequisites

  • Java 17+
  • Maven
  • Docker and Docker Compose

Steps to Run

  1. 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.

  2. Start the microservices: Start each of the Spring Boot applications in the following order:

    • discovery-service
    • inventory-service
    • order-service
    • gateway-service

    You can do this from your IDE (e.g., IntelliJ IDEA) or using Maven:

    # For each service
    mvn spring-boot:run

How to Use

Endpoints

Testing the Functionality

  1. 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.

  2. 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-service will start returning cached data from the fallback method: {"data":"cached-data","fromCache":true}.
  3. 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.

  4. Monitoring:

    • Open Grafana and create a dashboard for Resilience4j metrics (e.g., resilience4j_circuitbreaker_state).
    • Open Zipkin to trace distributed requests between services.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages