Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/anilerc/circuit-breaker-resilience4j-redis-spring
- Owner: anilerc
- Created: 2023-12-31T23:17:02.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-01-01T14:01:33.000Z (11 months ago)
- Last Synced: 2024-01-01T16:22:47.501Z (11 months ago)
- Topics: backend-engineering, circuit-breaker, microservices, redis, resilience4j, spring-boot, system-design
- Language: Java
- Homepage:
- Size: 199 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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