Getting Started with Alibaba Sentinel for Rate Limiting and Circuit Breaking in Spring Boot

This article introduces Alibaba Sentinel, explains its key features for traffic control and circuit breaking, and provides step‑by‑step instructions with code samples to set up the Sentinel dashboard, integrate it into a Spring Boot microservice, configure rate‑limiting rules, and verify the protection in action.

Top Architect
Top Architect
Top Architect
Getting Started with Alibaba Sentinel for Rate Limiting and Circuit Breaking in Spring Boot

Sentinel is an open‑source flow‑control and circuit‑breaker framework from Alibaba that includes a visual dashboard for monitoring and managing traffic.

It is widely used in microservice architectures to limit request rates, protect services from overload, and implement graceful degradation.

Key Features

Rich application scenarios : Handles burst traffic such as flash sales, message peak shaving, and real‑time circuit breaking for downstream services.

Real‑time monitoring : Provides per‑instance and aggregated metrics with second‑level granularity.

Extensive ecosystem : Offers out‑of‑the‑box integrations with Spring Cloud, Dubbo, gRPC, etc.

Pluggable SPI : Allows custom rule management and data source adapters.

Running the Dashboard (Server)

Download the Sentinel dashboard JAR from the releases page and start it with the default settings: java -jar sentinel-dashboard-1.6.0.jar You can also customize the port and dashboard address:

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

After launching, open http://localhost:8080 and log in with username sentinel and password sentinel. The dashboard will be empty until a client registers.

Setting Up the Client Application

Create a Spring Boot project and add the following Maven pom.xml (excerpt):

<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
    </parent>
    ...
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- Sentinel integration -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>0.2.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

Configure the dashboard address in application.yml:

spring:
  application:
    name: baobanserver
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080
      #eager: true   # uncomment to disable lazy loading

If port 8080 is occupied, change the server port (e.g., to 8888) in the same file.

Define a Simple Controller

@RestController
public class TestController {
    @GetMapping("/hello")
    public String hello() {
        return "Hello Sentinel";
    }
}

Run the Spring Boot application. The dashboard will now list the service and automatically generate default rules.

Because Sentinel uses lazy loading, the service appears only after the first request. To enable eager registration, uncomment the #eager: true line in application.yml.

Configure a Rate‑Limiting Rule

In the dashboard, navigate to the flow control section of the /hello endpoint and set the threshold to 1 request per second.

Now repeatedly call http://localhost:8080/hello. After the first request, subsequent calls are blocked, demonstrating that the flow control rule is active.

This completes a basic Sentinel integration: a dashboard, client registration, rule configuration, and verification of rate limiting.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaSpring Bootsentinelcircuit breaker
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

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.