After you modify instance weights in the Microservices Engine (MSE) console, traffic may not distribute according to the new weights. Nacos weights are metadata properties -- your application framework must explicitly support weighted routing for weight changes to affect traffic.
How Nacos weights work
Nacos instance weights are relative values. When you update a weight in the MSE console, the new value is pushed to all connected Nacos clients as part of the instance metadata. However, Nacos does not enforce traffic distribution. The client-side framework reads the weight and applies it during load balancing.
A weight of 0 removes the instance from traffic. For non-zero weights, the expected probability of routing to an instance is:
instance weight / sum of all instance weightsFor example, two instances with weights 3 and 1 receive 75% and 25% of traffic, respectively -- but only if the framework implements weighted selection.
Identify the cause
| Cause | Symptoms | Affected frameworks |
|---|---|---|
| Framework treats weight as binary | Traffic distributes evenly across all instances with non-zero weight | Spring Cloud Alibaba (default config) |
| Framework uses its own load balancing | Weight changes are ignored; framework-specific load balancing rules apply | Dubbo, Spring Cloud Alibaba + LoadBalancer |
| Application does not read the weight field | Custom service discovery code skips the weight property | Custom Nacos client implementations |
Solution by framework
Spring Cloud Alibaba
By default, Spring Cloud Alibaba treats Nacos weights as binary: zero means no traffic, non-zero means equal traffic. To enable weighted load balancing, activate the Nacos-aware load balancer.
Add the following to application.properties or application.yml:
spring.cloud.loadbalancer.nacos.enabled=trueIf you use Spring Cloud LoadBalancer directly, enable the WeightedServiceInstanceListSupplier:
spring.cloud.loadbalancer.configurations=weightedOr configure programmatically:
public class CustomLoadBalancerConfiguration {
@Bean
public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier(
ConfigurableApplicationContext context) {
return ServiceInstanceListSupplier.builder()
.withDiscoveryClient()
.withCaching()
.withWeighted()
.build(context);
}
}Dubbo
Dubbo has its own load balancing configuration and does not read Nacos instance weights by default. Configure weight-based load balancing at the global, interface, or method level.
Global configuration (application.yml):
dubbo:
consumer:
loadbalance: roundrobinInterface-level configuration (provider side):
@DubboService(loadbalance = "roundrobin")
public class DemoServiceImpl implements DemoService {}Interface-level configuration (consumer side, takes priority):
@DubboReference(loadbalance = "roundrobin")
private DemoService demoService;Dubbo supports the following load balancing algorithms:
| Algorithm | Configuration value | Weight support |
|---|---|---|
| Weighted random | random (default) | Yes |
| Weighted round robin | roundrobin | Yes |
| Least active + weighted random | leastactive | Yes |
| Shortest response + weighted random | shortestresponse | Yes |
| Consistent hash | consistenthash | No |
With random or roundrobin, Dubbo uses its own weight system. To use Nacos instance weights, implement a custom LoadBalance extension that reads the Nacos weight field.
Custom Nacos client implementations
If your application calls the Nacos API directly, confirm that your addressing logic reads the weight field.
Option 1: Use selectOneHealthyInstance (recommended)
The Nacos client selectOneHealthyInstance method performs weighted random selection based on instance weights:
NamingService namingService = NacosFactory.createNamingService(properties);
// Returns a single instance selected by weighted random
Instance instance = namingService.selectOneHealthyInstance("your-service-name");Option 2: Implement custom weighted selection
If you retrieve the full instance list, apply weight-based selection manually:
NamingService namingService = NacosFactory.createNamingService(properties);
List<Instance> instances = namingService.getAllInstances("your-service-name");
// Filter healthy instances and apply weighted random selection
List<Instance> healthy = instances.stream()
.filter(Instance::isHealthy)
.filter(i -> i.getWeight() > 0)
.collect(Collectors.toList());
// Calculate total weight
double totalWeight = healthy.stream()
.mapToDouble(Instance::getWeight)
.sum();
// Weighted random selection
double random = ThreadLocalRandom.current().nextDouble() * totalWeight;
double cumulative = 0;
for (Instance inst : healthy) {
cumulative += inst.getWeight();
if (random < cumulative) {
// Use this instance
break;
}
}For the full API reference, see Nacos Java SDK.
Verify weight-based routing
After applying the fix, verify that weights take effect:
Set instance A to weight 1 and instance B to weight 9.
Send 100 requests to the service.
Check the access logs of each instance. Instance B should receive approximately 90% of the requests.
If traffic still distributes evenly, check the following:
The load balancer configuration change has been deployed and the application has restarted.
No other load balancing rules (such as service mesh policies or gateway-level routing) override the framework-level configuration.
Instance weights are non-zero and correctly reflected in the Nacos console.