Prev Next

Spring / Resilience4j Interview questions

What is the purpose of the Decorators class?

The Decorators class provides a fluent builder for composing multiple resilience patterns around a single call, without hand-nesting one decorator function inside another.

Instead of writing CircuitBreaker.decorateSupplier(cb, RateLimiter.decorateSupplier(rl, supplier)) by hand, you write Decorators.ofSupplier(supplier).withCircuitBreaker(cb).withRateLimiter(rl).decorate(), which reads top-to-bottom and keeps the composition order explicit and easy to change.

It supports every core module - CircuitBreaker, Retry, RateLimiter, Bulkhead, TimeLimiter, Cache, and even a plain fallback - and works with Supplier, Runnable, Function, and CompletionStage-based calls alike.

The Decorators class exists mainly to:
Decorators.ofSupplier(...).withCircuitBreaker(cb).withRetry(retry).decorate() is equivalent in effect to:

More Related questions...

What is Resilience4j? What are the core modules of Resilience4j? What is a Circuit Breaker in Resilience4j? What are the states of a CircuitBreaker? What is the Retry module used for? What is a RateLimiter in Resilience4j? What is the Bulkhead pattern in Resilience4j? What is a TimeLimiter in Resilience4j? What is the Cache module in Resilience4j? How do you add Resilience4j to a Spring Boot project? What is the purpose of the Decorators class? Define fallback method in Resilience4j? What are the types of Bulkhead implementations? List the key configuration properties of a CircuitBreaker? How do you apply @CircuitBreaker in a Spring Boot service? Why is Resilience4j often preferred over Hystrix? How does the sliding window work in CircuitBreaker? What is the difference between COUNT_BASED and TIME_BASED sliding windows? How is failure rate calculated in a CircuitBreaker? What is the difference between CircuitBreaker and Bulkhead? How does the half-open state behave in a CircuitBreaker? Why do we use recordExceptions versus ignoreExceptions? When should you use RateLimiter instead of Bulkhead? What happens when a CircuitBreaker transitions to OPEN? How is Resilience4j's Retry different from a plain retry loop? Explain the execution flow of a call decorated with CircuitBreaker, Retry, and Bulkhead together? How do you combine multiple Resilience4j decorators using the Decorators class? Which is better and why: SemaphoreBulkhead or ThreadPoolBulkhead? How can you optimize CircuitBreaker configuration for a high-throughput service? How do you troubleshoot a CircuitBreaker that never opens despite failures? Explain the lifecycle of a CircuitBreaker instance? What is the difference between TimeLimiter and a plain timeout? How does RegistryEventConsumer work in Resilience4j? Why does Resilience4j rely on functional interfaces like Supplier and Function? How do you monitor Resilience4j metrics with Micrometer? What is the difference between waitDurationInOpenState and permittedNumberOfCallsInHalfOpenState? How do you write a unit test for a CircuitBreaker-protected method? Explain the internal working of exponential backoff in the Retry module? What is the difference between CallNotPermittedException and other Resilience4j exceptions? How do you use event publishers to log CircuitBreaker state transitions? When would you choose a RateLimiter over a Bulkhead for protecting a downstream call? How does Resilience4j integrate with reactive streams in WebFlux? What is the difference between recordException and recordResult predicates? Explain the internal working of automaticTransitionFromOpenToHalfOpenEnabled? How do you configure Resilience4j using application.yml in Spring Boot? What is the difference between the Resilience4j Cache module and a plain in-memory cache like Guava? How can you optimize retry strategies to avoid retry storms? Explain the execution flow when a fallback method itself throws an exception? How do you troubleshoot memory growth caused by an unbounded ThreadPoolBulkhead queue? Explain how Resilience4j's modular design influences microservice resilience architecture at scale?
Show more question and Answers...


Comments & Discussions