Spring / Resilience4j Interview questions
Why does Resilience4j rely on functional interfaces like Supplier and Function?
Building around Supplier, Function, Runnable, Callable, and CompletionStage means Resilience4j can decorate any piece of existing code that already fits one of those shapes, without requiring it to extend a base class or implement a library-specific command interface the way Hystrix's HystrixCommand did.
It also makes composition trivial: because a decorated call is still just a Supplier (or whichever type it started as), it can be passed to another decorator, stored, tested, or composed with standard Java functional idioms like Function.andThen - there's no special "decorated" type with its own rules to learn.
This design also keeps the library framework-agnostic - the same core decorators work in a plain Java application, a Spring Boot service, or a reactive pipeline, since none of them depend on inheriting from Resilience4j-specific base types.
More Related questions...