How to Set Up Alibaba Sentinel for Rate Limiting in a Spring Boot Microservice

This guide walks you through installing Alibaba Sentinel’s dashboard, configuring a Spring Boot client, defining flow rules, and verifying that request throttling works, providing all necessary commands, Maven snippets, YAML settings, and UI screenshots for a complete end‑to‑end rate‑limiting solution.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
How to Set Up Alibaba Sentinel for Rate Limiting in a Spring Boot Microservice

Introduction

Sentinel is an open‑source rate‑limiting and circuit‑breaker framework from Alibaba that includes a visual dashboard for monitoring and rule management. It is widely used in microservice architectures to protect services from overload, burst traffic, and downstream failures.

Key Features

Rich application scenarios : Handles flash‑sale spikes, message peak‑shaving, and real‑time circuit breaking.

Real‑time monitoring : Shows per‑instance and aggregated metrics in the dashboard.

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

Extensible SPI : Allows custom rule management and data‑source adapters.

Running the Sentinel Dashboard (Server)

Download the latest sentinel-dashboard JAR from the GitHub releases page ( https://github.com/alibaba/Sentinel/releases) and start it: java -jar sentinel-dashboard-1.6.0.jar The dashboard runs on port 8080 by default. Open http://localhost:8080 and log in with the default username/password sentinel.

Sentinel dashboard login screen
Sentinel dashboard login screen

Setting Up the Spring Boot Client

Create a Spring Boot project and add the following Maven dependencies:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>sentinel-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.SR1</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </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>

Note: Use version 0.2.x for Spring Boot 2.x projects; older Spring Boot 1.x requires 0.1.x.

Configuration

Add the Sentinel dashboard address to application.yml:

spring:
  application:
    name: sentinel-demo
  cloud:
    sentinel:
      transport:
        dashboard: localhost:8080
      #eager: true   # Uncomment to disable lazy loading

Controller Example

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

Run the Spring Boot application. The dashboard will initially show no client because Sentinel loads rules lazily.

Defining a Flow Rule

After the first request to /hello, the client appears in the dashboard. Open the “Flow Control” tab for the /hello resource and set the QPS threshold to 1. This limits the endpoint to one request per second.

Setting flow rule in Sentinel UI
Setting flow rule in Sentinel UI

Verification

Send multiple rapid requests to /hello. The dashboard shows the QPS statistics and the requests exceeding the limit are blocked, confirming that rate limiting is active.

Requests blocked after exceeding limit
Requests blocked after exceeding limit

By following these steps you have a functional Sentinel setup that provides real‑time monitoring, rule management, and effective traffic throttling for your Spring Boot microservice.

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.

JavaMicroservicesSpring Bootsentinelrate limitingcircuit breaker
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow 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.