How to Add Zero‑Code Flow‑Control and Degradation to Any Microservice Method with MSE Sentinel
This guide explains how to use Alibaba Cloud's MSE Sentinel to protect microservice stability by configuring runtime flow‑control and degradation rules for any method—without writing additional code—covering background, scenarios, annotation and SDK approaches, rule configuration, and monitoring results.
Microservice stability is a major concern as systems evolve from monoliths to distributed architectures, leading to complex dependencies and high‑availability challenges, especially during traffic spikes such as mask purchases or online class registrations.
Background
Two common instability scenarios are identified: (1) a service’s own traffic exceeding its capacity, causing overload, high CPU/load, and potential crashes; (2) cascading failures when a service depends on other unstable services, leading to thread‑pool exhaustion and chain‑wide outages.
To mitigate these, Alibaba Cloud MSE Service Governance leverages the Sentinel component, offering flow control, concurrency limits, circuit breaking, hotspot protection, and adaptive system protection across microservices, cloud‑native gateways, and service mesh.
Runtime Enhance Capability
The runtime Enhance feature enables one‑click flow‑control and degradation for any point—Web, RPC, SQL, Redis, or custom business methods—without modifying source code.
Demo Application
A simple Spring Boot demo defines a controller with a method a(HttpServletRequest request). The method reads request headers and calls a downstream service via restTemplate.getForObject("http://sc-B/b", String.class).
@SpringBootApplication
public class AApplication {
public static void main(String[] args) {
SpringApplication.run(AApplication.class, args);
}
@RestController
class AController {
@GetMapping("/a")
public String restA(HttpServletRequest request) {
return a(request);
}
private String a(HttpServletRequest request) {
// header processing and downstream call
}
}
}Initially, only the /a endpoint is observable in monitoring.
Adding Sentinel Protection
Two approaches are shown:
Annotation : Use
@SentinelResource("com.alibabacloud.mse.demo.AApplication.AController:a")on the target method (subject to AOP limitations).
SDK : Manually acquire an Entry via SphU.entry("HelloWorld"), wrap the method body, and handle BlockException to block traffic.
Both require adding Sentinel dependencies and may involve code changes and redeployment.
Zero‑Code Flow‑Control via Runtime White‑Screen Rules
To avoid code changes, MSE provides a UI to configure white‑screen (runtime) rules:
Select the target application and custom point‑cut (e.g., the method com.alibabacloud.mse.demo.AApplication.AController#a).
Define a WhiteScreenRule = Target + Action where Target includes ResourceTarget (Web/RPC/SQL/custom method), WorkloadTarget (specific instances), and TrafficCondition (abnormal/slow calls, gray tags).
Action can collect diagnostic context, log the chain, enforce flow‑control/degradation, or tag traffic.
After configuring, the method becomes visible in the custom instrumentation monitor, and flow‑control rules can be added.
Configuring Flow‑Control Rules
In the interface overview, click “Add Protection Rule” and create a simple QPS rule, e.g., limit the method to 1 request per second per instance. Once applied, the monitoring page shows rejected traffic (HTTP 429 for web, exceptions for DAO/Java methods) and confirms the rule’s effect.
Summary
The runtime white‑screen capability abstracts protection as a rule combining target selection and actions, enabling zero‑code flow‑control, degradation, and context collection for any microservice point. Future MSE releases will integrate these rules with dynamic Enhance logging for comprehensive traffic governance.
Sentinel’s proven use in Alibaba’s e‑commerce, finance, education, gaming, and enterprise sectors demonstrates its effectiveness for large‑scale, cloud‑native environments.
Alibaba Cloud Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
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.
