Spring Cloud Spring Cloud Circuit Breaker & Resilience 1 — Questions and Answers
Question 1: Which library replaced Hystrix as the recommended circuit breaker in Spring Cloud after Netflix put Hystrix in maintenance mode?
- Resilience4j (Correct answer)
- Sentinel
- Envoy
- Istio
Correct answer: Resilience4j
Resilience4j became the recommended circuit breaker library in Spring Cloud after Netflix officially put Hystrix into maintenance mode.
Question 2: What are the three states a circuit breaker cycles through in the circuit breaker pattern?
- Closed, Open, Half-Open (Correct answer)
- Active, Inactive, Pending
- Running, Stopped, Paused
- Enabled, Disabled, Testing
Correct answer: Closed, Open, Half-Open
A circuit breaker transitions between Closed (normal operation), Open (rejecting calls after failures), and Half-Open (testing recovery) states.
Question 3: Which annotation is used in Spring Cloud Resilience4j to apply a circuit breaker declaratively to a method?
- @CircuitBreaker (Correct answer)
- @HystrixCommand
- @Fallback
- @Resilient
Correct answer: @CircuitBreaker
The @CircuitBreaker annotation from Spring Cloud Resilience4j is placed on methods to enable circuit breaker behavior declaratively.
Question 4: What is the role of a fallback method in a Spring Cloud circuit breaker setup?
- Provide an alternative response when the primary method fails or the circuit is open (Correct answer)
- Roll back database transactions on failure
- Automatically retry the failed operation
- Log errors to an external monitoring system
Correct answer: Provide an alternative response when the primary method fails or the circuit is open
A fallback method returns a default or cached response when the circuit is open or the primary method throws an exception, maintaining graceful degradation.
Question 5: Which Resilience4j configuration property sets the percentage of failures required to trip the circuit breaker to Open state?
- failureRateThreshold (Correct answer)
- openThreshold
- breakerLimit
- circuitOpenRate
Correct answer: failureRateThreshold
failureRateThreshold specifies the failure percentage within the sliding window that triggers the circuit breaker to transition to the Open state.
Question 6: What does the 'slidingWindowSize' property control in a Resilience4j circuit breaker configuration?
- The number of recent calls analyzed to calculate the failure rate (Correct answer)
- The timeout duration for each individual request
- The interval between retry attempts
- The maximum size of the thread pool
Correct answer: The number of recent calls analyzed to calculate the failure rate
slidingWindowSize defines how many recent calls (COUNT_BASED) or seconds (TIME_BASED) are used to calculate the failure rate for circuit breaker decisions.
Question 7: Which Spring Cloud starter dependency integrates Resilience4j as the circuit breaker implementation for Spring Boot 3 projects?
- spring-cloud-starter-circuitbreaker-resilience4j (Correct answer)
- resilience4j-spring-cloud
- spring-boot-starter-resilience4j
- spring-cloud-resilience4j-starter
Correct answer: spring-cloud-starter-circuitbreaker-resilience4j
The spring-cloud-starter-circuitbreaker-resilience4j dependency provides Spring Cloud's Circuit Breaker abstraction backed by Resilience4j.
Which library replaced Hystrix as the recommended circuit breaker in Spring Cloud after Netflix put Hystrix in maintenance mode?