In-depth Guide to Alibaba Sentinel: Core Concepts, Demo, and Implementation
This article provides a comprehensive introduction to Alibaba Sentinel, covering its purpose, core concepts such as resources and rules, step‑by‑step demos for basic usage and Spring integration, and an analysis of its internal processor slots and flow‑control mechanisms.
Sentinel is an open‑source flow‑control component from Alibaba designed for distributed, heterogeneous microservice architectures, offering traffic shaping, rate limiting, circuit breaking, system overload protection, and hotspot traffic defense.
Core Concepts
Resource : The protected object, typically an HTTP or RPC interface, identified by a name (e.g., the request path).
Rule : The condition that triggers limiting, such as a QPS threshold, which is applied to a specific resource.
Demo
Basic usage – Add the <dependency>com.alibaba.csp:sentinel-core:1.8.6</dependency> Maven dependency, then load a flow rule for the resource sayHello with a QPS limit of 2, and invoke the resource via SphU.entry("sayHello") . The demo prints whether the call is allowed or blocked.
Spring integration – Add Spring Boot and Sentinel starter dependencies, define a @RestController with a /sayHello endpoint, and configure the Sentinel dashboard address in application.yml . The dashboard (started with java -jar sentinel-dashboard.jar ) allows dynamic rule management.
Core Principles
Sentinel creates a ProcessorSlot chain for each resource. The default chain consists of eight slots:
NodeSelectorSlot – selects the appropriate statistical Node for the current entry.
ClusterBuilderSlot – builds ClusterNode (aggregate) and OriginNode (per‑caller) statistics.
LogSlot – logs exceptions and events.
StatisticSlot – updates counters such as request count, thread count, and QPS using a sliding‑window algorithm.
AuthoritySlot – enforces black‑/white‑list access control.
SystemSlot – limits based on system‑wide metrics (CPU, load, thread count, etc.).
FlowSlot – applies flow‑control rules (direct, related, chain) and decides whether to allow or block a request.
DegradeSlot – performs circuit‑breaking based on slow‑call ratio, exception ratio, or exception count.
Each slot can be extended via SPI to customize Sentinel’s behavior.
Rule Details
Flow rules include fields such as resource , threshold type (QPS or thread count), cluster mode , control behavior (fast‑fail, warm‑up, queueing), and optional origin to limit specific callers.
Summary
Sentinel’s power lies in its lightweight statistical nodes and a flexible processor‑slot chain that together enable precise rate limiting, circuit breaking, and system protection for microservices.
Final Note
The author encourages readers to like, share, and follow for more technical content, and promotes a paid knowledge community for deeper Spring, MyBatis, RocketMQ, and DDD microservice tutorials.
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
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.