All Products
Search
Document Center

Microservices Engine:Instance weight changes not taking effect on MSE Nacos

Last Updated:Mar 11, 2026

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 weights

For 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

CauseSymptomsAffected frameworks
Framework treats weight as binaryTraffic distributes evenly across all instances with non-zero weightSpring Cloud Alibaba (default config)
Framework uses its own load balancingWeight changes are ignored; framework-specific load balancing rules applyDubbo, Spring Cloud Alibaba + LoadBalancer
Application does not read the weight fieldCustom service discovery code skips the weight propertyCustom 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=true

If you use Spring Cloud LoadBalancer directly, enable the WeightedServiceInstanceListSupplier:

spring.cloud.loadbalancer.configurations=weighted

Or 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: roundrobin

Interface-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:

AlgorithmConfiguration valueWeight support
Weighted randomrandom (default)Yes
Weighted round robinroundrobinYes
Least active + weighted randomleastactiveYes
Shortest response + weighted randomshortestresponseYes
Consistent hashconsistenthashNo

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:

  1. Set instance A to weight 1 and instance B to weight 9.

  2. Send 100 requests to the service.

  3. 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.

References