You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project demonstrates the implementation of the Fallback Pattern with Circuit Breaker in Java. The Fallback Pattern is used to handle failures gracefully by providing alternative solutions when the primary service fails. The Circuit Breaker pattern is integrated to prevent cascading failures and to monitor the health of the primary service.
6
+
7
+
## Features
8
+
9
+
-**Primary Service**: The main service that attempts to retrieve data.
10
+
-**Fallback Service**: A backup service that provides data when the primary service fails.
11
+
-**Circuit Breaker**: Monitors the health of the primary service and prevents further calls when the service is deemed unhealthy.
12
+
-**Service Monitor**: Tracks the performance metrics of the services.
13
+
-**Rate Limiter**: Limits the number of requests to prevent overload.
14
+
-**Service Exception**: Custom exceptions to handle service-specific errors.
15
+
16
+
## Components
17
+
18
+
-**Service Interface**: Defines the contract for services.
19
+
-**RemoteService**: Implementation of the primary service that makes HTTP calls.
20
+
-**LocalCacheService**: Implementation of the fallback service that provides cached data.
21
+
-**FallbackService**: Manages the primary and fallback services, integrating the circuit breaker and rate limiter.
22
+
-**DefaultCircuitBreaker**: Implementation of the circuit breaker with state transitions and failure tracking.
23
+
-**ServiceMonitor**: Monitors and records the performance metrics of the services.
24
+
-**Service Exception**: Custom exception class to handle errors specific to service operations.
25
+
26
+
## Usage
27
+
28
+
To run the application, execute the `App` class. The application will attempt to retrieve data using the primary service and fallback to the cached data if the primary service fails.
29
+
30
+
## Reflection
31
+
32
+
This assignment provided a practical application of Object-Oriented Analysis and Design (OOAD) principles. By implementing the Fallback Pattern with Circuit Breaker, I was able to apply concepts such as encapsulation, polymorphism, and separation of concerns. Each component in the system has a clear responsibility, and the use of interfaces allows for flexibility and easy substitution of different implementations.
33
+
34
+
One of the challenges faced was ensuring thread safety and proper synchronization, especially in the circuit breaker and rate limiter components. To overcome this, I used concurrent data structures and synchronized methods to manage state transitions and request handling. Additionally, integrating the health monitoring and metrics collection required careful consideration of performance and resource management, which was addressed by using scheduled executors and atomic variables.
0 commit comments