What is the main purpose of a circuit breaker in system design?
A circuit breaker helps prevent a system from repeatedly trying to perform an operation that is likely to fail, protecting resources and allowing the system to recover gracefully.
Click to reveal answer
intermediate
How does Resilience4j implement the circuit breaker pattern?
Resilience4j provides a lightweight, easy-to-use circuit breaker that monitors failures and controls calls to external services by opening, closing, or half-opening the circuit based on failure rates and timeouts.
Click to reveal answer
beginner
What are the three states of a circuit breaker in Resilience4j?
Closed (normal operation), Open (calls are blocked), and Half-Open (test calls allowed to check if service has recovered).
Click to reveal answer
intermediate
In Resilience4j, what happens when the failure rate exceeds the threshold configured in the circuit breaker?
The circuit breaker transitions from Closed to Open state, blocking further calls to the failing service for a configured wait duration.
Click to reveal answer
intermediate
Why is the Half-Open state important in a circuit breaker?
It allows the system to test if the external service has recovered by allowing a limited number of calls before fully closing the circuit again.
Click to reveal answer
What state does a circuit breaker enter when it detects too many failures?
AOpen
BClosed
CHalf-Open
DDisabled
✗ Incorrect
When failures exceed the threshold, the circuit breaker opens to stop calls to the failing service.
Which Resilience4j feature allows you to automatically retry calls after a failure?
ACircuit Breaker
BRate Limiter
CBulkhead
DRetry
✗ Incorrect
The Retry feature in Resilience4j automatically retries failed calls based on configuration.
In Resilience4j, what does the Half-Open state do?
ABlocks all calls
BAllows limited test calls
CAllows all calls
DDisables the circuit breaker
✗ Incorrect
Half-Open state allows a limited number of calls to test if the service has recovered.
Which metric does Resilience4j use to decide when to open the circuit breaker?
AFailure rate
BCPU usage
CMemory usage
DResponse time
✗ Incorrect
Resilience4j opens the circuit breaker when the failure rate exceeds a configured threshold.
What is the benefit of using a circuit breaker in microservices?
AImproves UI responsiveness
BSpeeds up network traffic
CPrevents cascading failures
DIncreases database size
✗ Incorrect
Circuit breakers prevent cascading failures by stopping calls to failing services.
Explain how a circuit breaker works in Resilience4j and why it is useful in a microservices architecture.
Think about how it protects your system from repeated failures.
You got /5 concepts.
Describe the configuration options you can set for a Resilience4j circuit breaker and their impact on system behavior.
Consider how these settings control when and how the circuit breaker opens or closes.
You got /5 concepts.
Practice
(1/5)
1. What is the primary purpose of using a circuit breaker like Resilience4j in a Spring Boot application?
easy
A. To automatically scale the application horizontally
B. To increase the speed of database queries
C. To encrypt data sent between microservices
D. To prevent repeated calls to a failing service and allow recovery
Solution
Step 1: Understand circuit breaker role
A circuit breaker stops calls to a failing service temporarily to avoid cascading failures.
Step 2: Identify the main benefit
This helps the system recover and prevents wasting resources on repeated failing calls.
Final Answer:
To prevent repeated calls to a failing service and allow recovery -> Option D
4. Consider this incorrect Resilience4j usage in Spring Boot:
@CircuitBreaker(name = "serviceB", fallback = "fallbackMethod")
public String fetchData() {
// call external API
}
What is the main issue with this code?
medium
A. The method fetchData must return void
B. Circuit breaker name cannot be "serviceB"
C. The fallback method name should be specified with fallbackMethod, not fallback
D. The annotation @CircuitBreaker cannot be used on public methods
Solution
Step 1: Check annotation attribute names
The correct attribute for fallback method name is fallbackMethod, not fallback.
Step 2: Validate other conditions
Method return type and visibility are valid; circuit breaker name can be any string.
Final Answer:
The fallback method name should be specified with fallbackMethod, not fallback -> Option C
Quick Check:
Correct fallback attribute = fallbackMethod [OK]
Hint: Use fallbackMethod attribute for fallback name [OK]
Common Mistakes:
Using 'fallback' instead of 'fallbackMethod'
Thinking method must be void
Assuming circuit breaker name is restricted
5. You want to design a Spring Boot microservice that calls an unstable external payment API. Using Resilience4j circuit breaker, which approach best ensures system stability and graceful degradation?
hard
A. Apply @CircuitBreaker with a fallback method returning a cached payment status
B. Remove circuit breaker and rely on retries only
C. Use @CircuitBreaker without fallback to fail fast
D. Disable circuit breaker and increase thread pool size
Solution
Step 1: Understand system stability needs
Using a circuit breaker prevents repeated calls to the unstable API, avoiding overload.
Step 2: Importance of fallback for graceful degradation
A fallback method returning cached or default data keeps the system responsive during failures.
Step 3: Evaluate other options
Retries alone can worsen overload; no fallback causes failures; increasing threads doesn't solve API instability.
Final Answer:
Apply @CircuitBreaker with a fallback method returning a cached payment status -> Option A