Backend Development 38 min read

Comprehensive Guide to Alibaba Sentinel: Installation, Dashboard, Flow Control, Degrade Rules, Hotspot Parameters, Persistence, Cluster Flow Control, and Integration with Spring Cloud

This article provides an in‑depth tutorial on Alibaba Sentinel, covering its core concepts, installation of the dashboard, version selection, flow‑control configuration, degrade rules, hotspot parameter limiting, system adaptive protection, custom block handlers, blacklist/whitelist settings, rule persistence with Nacos, push‑mode synchronization, and cluster flow‑control setup for microservice applications.

Code Ape Tech Column
Code Ape Tech Column
Code Ape Tech Column
Comprehensive Guide to Alibaba Sentinel: Installation, Dashboard, Flow Control, Degrade Rules, Hotspot Parameters, Persistence, Cluster Flow Control, and Integration with Spring Cloud

1. Introduction

Sentinel is an open‑source flow‑control and circuit‑breaker framework from Alibaba, proven in large‑scale events like Double‑11 for nearly a decade.

2. What is Sentinel?

Sentinel protects services from overload by controlling traffic, circuit breaking, and system load. It offers rich scenarios, real‑time monitoring, extensive ecosystem integrations (Spring Cloud, Dubbo, gRPC, Quarkus), multi‑language support, and a flexible SPI extension mechanism.

3. Sentinel vs. Hystrix

Sentinel is recommended over Hystrix for modern microservices.

4. Version Selection

When using Spring Cloud Alibaba, align Sentinel version with the spring-cloud-alibaba-dependencies version (e.g., 2.2.1.RELEASE → Sentinel 1.7.1).

5. Installing the Sentinel Dashboard

Download the appropriate .jar (e.g., sentinel-dashboard-1.7.1.jar) and run:

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.7.1.jar

Default credentials are sentinel/sentinel . After startup, access http://localhost:8080 to view the dashboard.

6. Registering a Microservice with Sentinel

Add the Sentinel starter dependency and configure the dashboard address in application.yml :

spring:
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080

Create a test controller (e.g., /sentinel/test ) and verify that the service appears in the dashboard after the first request.

7. Flow Control Configuration

Flow rules consist of resource , count , grade (QPS or concurrency), limitApp , strategy , and controlBehavior . The rule class is com.alibaba.csp.sentinel.slots.block.flow.FlowRule .

7.1 Flow Control Modes

Fast Fail (default): immediate rejection when QPS exceeds the threshold.

Warm‑Up: gradual increase of allowed QPS using a token‑bucket algorithm.

Queueing (Rate Limiter): requests are queued with a timeout.

7.2 Flow Control Strategies

Direct Reject

Associated (limit based on another resource)

Chain (limit based on the entry resource)

8. Degrade (Circuit‑Breaker) Rules

Degrade rules are represented by com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule and support three strategies:

Average response time (RT) – triggers when RT exceeds a threshold.

Exception ratio – triggers when the exception ratio exceeds a configured value.

Exception count – triggers when the number of exceptions exceeds a threshold.

9. Hotspot Parameter Limiting

Hotspot limiting protects frequently accessed parameters (e.g., product IDs) using an LRU cache and token‑bucket algorithm. The rule class is com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule . Example: limit QPS of the first method argument to 1 request per second, with an exception for p1=100 .

10. System Adaptive Protection

System rules monitor load, CPU usage, average RT, concurrent threads, and entrance QPS. When thresholds are breached, Sentinel applies protection. Example shown for entrance QPS.

11. Custom Block Handler

Use @SentinelResource with blockHandler (or blockHandlerClass ) to return custom messages when a request is blocked.

12. Exception Degrade (Fallback)

Configure fallback , fallbackClass , or defaultFallback in @SentinelResource to handle business exceptions. BlockHandler takes precedence over fallback when a BlockException occurs.

13. Black/White List

Authorization rules ( com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule ) control access based on request origin. Implement RequestOriginParser to define the origin (e.g., IP address).

14. Rule Persistence with Nacos (Push Mode)

Add sentinel-datasource-nacos dependency and configure spring.cloud.sentinel.datasource for flow and degrade rules. Rules are stored as JSON in Nacos and pushed to Sentinel automatically.

Example Flow Rule JSON

[
  {
    "resource": "/test",
    "limitApp": "default",
    "grade": 1,
    "count": 1,
    "clusterMode": false,
    "controlBehavior": 0,
    "strategy": 0,
    "warmUpPeriodSec": 10,
    "maxQueueingTimeMs": 500,
    "refResource": "rrr"
  }
]

15. Pushing Dashboard Changes Back to Nacos

Modify Sentinel Dashboard source to use Nacos DynamicRuleProvider and DynamicRulePublisher for flow rules, enabling two‑way synchronization.

16. Cluster Flow Control

Cluster flow control uses a Token Server (stand‑alone or embedded) and Token Clients. Configure one instance as the token server and others as clients via the dashboard or Nacos. This ensures consistent QPS limits across the cluster.

17. Gateway Rate Limiting

Sentinel also supports gateway (e.g., Spring Cloud Gateway) rate limiting; refer to the official documentation for details.

18. Integration with OpenFeign

Use Sentinel starter with OpenFeign to achieve circuit breaking and fallback handling for remote calls.

For the full source code and additional examples, refer to the linked GitHub repository or request it via the public account.

JavamicroservicesNacosSentinelRate LimitingSpring Cloudflow control
Code Ape Tech Column
Written by

Code Ape Tech Column

Former Ant Group P8 engineer, pure technologist, sharing full‑stack Java, job interview and career advice through a column. Site: java-family.cn

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.