Guideline:Migration from Hystrix to Sentinel

As microservices become more popular, the stability between services becomes more and more important. Technologies such as flow control, fault tolerance, and system load protection are widely used in microservice systems to improve the robustness of the system and guarantee the stability of the business, and to minimize system outages caused by excessive access traffic and heavy system load.

Hystrix, an open source latency and fault tolerance library of Netflix, has recently announced on its GitHub homepage that new features are no longer under development. It is recommended that developers use other open source projects that are still active.So what are the alternatives?

Last time, we introduced two alternatives in the article, “Resilience4j and Sentinel: Two Open-Source Alternatives to Netflix Hystrix

This article will help you migrate from Hystrix to Sentinel and help you get up to speed on using Sentinel.

Feature in HystrixMigration SolutionFeature in SentinelThread Pool Isolation / Semaphore IsolationSentinel does not support thread pool isolation; In Sentinel, flow control in thread count mode represents semaphore isolation. If you are using semaphore isolation, you can simply add flow rules for target resource.Thread Count Flow ControlCircuit BreakerSentinel supports circuit breaking by average response time, exception ratio and exception count. If you want to use circuit breaking in Sentinel, you cam simply configure degrade rules for target resource.Circuit breaking with various strategyCommand DefinitionYou can define your resource entry (similar to command key) via SphU API in Sentinel. Resource definition and rule configuration are separate.Resource Entry DefinitionCommand ConfigurationRules can be hardcoded through the xxxRuleManager API in Sentinel, and multiple dynamic rule data sources are also supported.Rule ConfigurationHystrixCommand annotationSentinel also provides annotation support (SentinelResource), which is easy to use.SentinelResource annotationSpring Cloud NetflixSentinel provides out-of-box integration modules for Servlet, Dubbo, Spring Cloud, and gRPC. If you were using Spring Cloud Netflix previously, it's east for you to migrate to Spring Cloud Alibaba.Spring Cloud Alibaba


The execution model of Hystrix is designed with a command pattern, HystrixCommand, which encapsulates the business logic and fallback logic into a single command object (HystrixCommand / HystrixObservableCommand). A simple example:

Sentinel does not specify an execution model, nor does it care how the code is executed. In Sentinel, what you should do is just to wrap your code with Sentinel API to define resources:

In Hystrix, you usually have to configure rules when the command is defined. In Sentinel, resource definitions and rule configurations are separate. Users first define resources for the corresponding business logic through the Sentinel API, and then configure the rules when needed. For details, please refer to this document.

Thread Pool Isolation

The advantage of thread pool isolation is that the isolation is relatively thorough, and it can be processed for the thread pool of a resource without affecting other resources. But the drawback is that the number of threads is large, and the overhead of thread context switching is very large, especially for low latency invocations. Sentinel does not provide such a heavy isolation strategy, but provides a relatively lightweight isolation strategy — thread count flow control as semaphore isolation.

Semaphore Isolation

Hystrix’s semaphore isolation is configured at Command definition, such as:

In Sentinel, semaphore isolation is provided as a mode of flow control (thread count mode), so you only need to configure the flow rule for the resource:

If you are using Sentinel dashboard, you can also easily configure the rules in dashboard.

Circuit Breaking

Hystrix circuit breaker supports error percentage mode. Related properties:

  1. circuitBreaker.errorThresholdPercentage: the threshold
  2. circuitBreaker.sleepWindowInMilliseconds: the sleep window when circuit breaker is open

For example:

In Sentinel, you only need to configure circuit breaking rules for resources that want to be automatically degraded. For example, the rules corresponding to the Hystrix example above:

If you are using Sentinel dashboard, you can also easily configure the circuit breaking rules in dashboard.

In addition to the exception ratio mode, Sentinel also supports automatic circuit breaking based on average response time and minute exceptions.

Annotation Support

Hystrix provides annotation support to encapsulate command and configure it. Here is an example of Hystrix annotation:

Hystrix rule configuration is bundled with command execution. We can configure rules for command in the commandProperties property of the @HystrixCommand annotation, such as:

Using Sentinel annotations is similar to Hystrix, as follows:

  1. Add the annotation support dependency: sentinel-annotation-aspectj and register the aspect as a Spring bean (if you are using Spring Cloud Alibaba then the bean will be injected automatically);
  2. Add the @SentinelResource annotation to the method that needs flow control and circuit breaking. You can set fallback or blockHandler functions in the annotation;
  3. Configure rules

For the details, you can refer to the annotation support document. An example for Sentinel annotation:

Then configure the rules:

  1. via API (e.g. DegradeRuleManager.loadRules(rules) method)
  • DegradeRule rule = new DegradeRule("getUserById") .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_RATIO) // exception ratio mode .setCount(0.5) // ratio threshold (0.5 -> 50%) .setTimeWindow(10); // sleep window (10s) // load the rules DegradeRuleManager.loadRules(Collections.singletonList(rule));
  1. via Sentinel dashboard


Sentinel has integration modules with Web Servlet, Dubbo, Spring Cloud and gRPC. Users can quickly use Sentinel by introducing adapter dependencies and do simple configuration. If you have been using Spring Cloud Netflix before, you may consider migrating to the Spring Cloud Alibaba.

Dynamic Configuration

Sentinel provides dynamic rule data-source support for dynamic rule management. The ReadableDataSource and WritableDataSource interfaces provided by Sentinel are easy to use.
The Sentinel dynamic rule data-source provides extension module to integrate with popular configuration centers and remote storage. Currently, it supports many dynamic rule sources such as Nacos, ZooKeeper, Apollo, and Redis, which can cover many production scenarios.


Follow me to keep abreast with the latest technology news, industry insights, and developer trends.