Comparisons
Failsafe vs Resilience4j
Failsafe and Resilience4j are similar libraries in what they aim to offer users. They do provide different user experiences though, and also have some different features that are worth noting:
General
- Failsafe has zero dependencies. Resilience4j depends on Vavr.
- Failsafe provides a uniform interface for performing executions against any policy combination. Resilience4j supports varying execution decorators for different policies.
- Failsafe offers a uniform ExecutionContext for any execution.
Async Support
- Failsafe offers async execution support for and any Runnable, Supplier, or CompletionStage, and any policy combination. Resilience4j offers async support for some policies via decorated CompletionStages.
- Failsafe offers async integration support.
- Failsafe offers configurable executors and custom schedulers.
- Failsafe offers cancellation and interruption support for all sync and async executions. Resilience4j supports cancellation via decorated CompletionStages.
- Failsafe extends interruption support to executions that run in a ForkJoinPool such as CompletableFutures. Resilience4j decorated CompletionStages cannot be interrupted.
- Failsafe’s RateLimiter and Bulkhead can wait asynchronously for a permit. Resilience4j’s RateLimiter and Bulkhead block while waiting.
Policies
- Failsafe provides a uniform interface for failure handling and event handling configuration. Resilience4j configuration for these varies across policies.
- Failsafe’s Timeout policy supports interrupts.
- Failsafe’s RateLimiter supports smooth and bursty rate limiting.
- Failsafe CircuitBreaker, RateLimiter, and Bulkhead can be used as standalone constructs.
- Resilience4j offers a Cache policy, which Failsafe doesn’t.
Other Features
- Failsafe offers standalone execution support.
- Failsafe provides strong typing across all of its APIs.
- Failsafe offers an extensible SPI for implementing custom policies.
- Resilience4j has a built-in named policy registry.
- Resilience4j offers some additional modules for 3rd party library integration.
References:
Failsafe vs Hystrix
Failsafe is intended to be a lightweight, general purpose library for handling any type of execution. Hystrix is more oriented around the execution of remote requests and offers additional features for that purpose. A few differences worth noting:
General
- Failsafe has zero dependencies. Hystrix has several external dependencies including Archais, Guava, ReactiveX, and Apache Commons Configuration.
- Failsafe offers several policies in addition to circuit breakers, which you can create and compose as needed. Hystrix is primarily an implementation of the circuit breaker and bulkhead patterns.
- Failsafe allows executable logic via simple lambda expressions, Runnables, and Suppliers. Hystrix requires that executable logic be placed in a HystrixCommand implementation.
Async Support
- Failsafe supports configurable thread pools in addition to the common pool. In Hystrix, asynchronous commands are executed on internally managed thread pools for particular dependencies.
- In Failsafe, asynchronous executions can be observed via event listeners and the resulting CompletableFuture. In Hystrix, asynchronous executions can be observed using RxJava Observables.
Policies
- Failsafe supports both count based and time based circuit breakers, with the ability to set any time window. Hystrix supports only time based circuit breakers, recording execution results per second, by default, and basing open/close decisions on the last second’s results.
- Failsafe circuit breakers support configurable success thresholds. Hystrix only performs a single execution when in half-open state to determine whether to close a circuit.
- Failsafe circuit breakers can be shared across different executions, so that if a failure occurs, all executions against that component will be halted by the circuit breaker.
- Failsafe circuit breakers can be used and operated as standalone constructs.