Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/anilerc/circuit-breaker-resilience4j-redis-spring

Fault tolerance is a crucial aspect of microservices system design. Implementation of the circuit breaker pattern using Resilience4j for services written in Java/Spring Boot, with Redis as a fallback caching mechanism.
https://github.com/anilerc/circuit-breaker-resilience4j-redis-spring

backend-engineering circuit-breaker microservices redis resilience4j spring-boot system-design

Last synced: 7 days ago
JSON representation

Fault tolerance is a crucial aspect of microservices system design. Implementation of the circuit breaker pattern using Resilience4j for services written in Java/Spring Boot, with Redis as a fallback caching mechanism.

Awesome Lists containing this project

README

        

### Building a Circuit Breaker with Redis & Resilience4j for Fault-Tolerant Java Microservices

#### Project Idea & Introduction

![System design / implementation diagramme.](diagramme/diagramme.png)

Fault tolerance is a crucial aspect of microservices system design. In this project, I built the circuit breaker pattern using Resilience4j for services written in Java/Spring Boot, with Redis as a fallback caching mechanism.

#### What is a Circuit Breaker for Microservices?
The circuit breaker pattern enables us to have resilient, fault-tolerant microservices by gracefully handling service failures and preventing system overloads. In microservices architecture, a circuit breaker acts as a safeguard against the failure of a service or an external dependency. It constantly monitors for failures and upon reaching a threshold, it "trips" to prevent further strain on the failing service. This helps in maintaining the system's stability and performance, as well as preventing failure chains.

#### Circuit Breaker Isolation: Prevent Cascading Failures
In distributed systems, services depend on each other. If one service fails, it can cascade and impact other services, leading to system-wide failures. Implementing a circuit breaker helps in isolating problems and ensuring system reliability.

#### Implementation Explanation
This project comprises two microservices: Publication and Comments. The Comments service is wrapped with a Resilience4J circuit breaker.
Normal Operation: Under normal conditions, requests to the Comments service are processed as usual.
Circuit Breaker Activation: When the Comments service fails or becomes unresponsive, the circuit breaker trips after a predefined threshold.
Redis as Fallback Cache: Once the circuit breaker is open, the system falls back to the last cached results from Redis, ensuring continued availability of data.
System Recovery: The circuit breaker periodically allows a limited number of requests to pass through to check if the underlying service is back to normal. If the service is healthy, the circuit breaker closes, and normal operation resumes.

#### Conclusion
This project further enhanced my competence in building fault-tolerant microservices in Java/Spring by using advanced patterns. Here, I also demonstrated the effective use of Redis for fallback caching, ensuring data availability even when parts of the system fail. The core idea I implemented here can be supported with further improvements.

###### I kindly invite you to check my other completed projects on Java microservices:
- Event-Driven CQRS & SAGA Choreography with Hexagonal Architecture
- Distributed transactions, event-driven microservices, Apache Kafka, Java, Spring Boot, ports & adapters pattern
- Implementing Distributed Microservices Communication with Spring Eureka & RabbitMQ
- Java, Spring Cloud Gateway, Spring Security, RabbitMQ, Eureka Discovery Server, distributed tracing