Mastering Service Routing: Strategies, Rules, and Real-World Examples

This article explains how service routing selects the most suitable service node for a consumer, covering scenarios such as grouped calls, gray releases, traffic switching, read/write separation, and provides concrete condition, whitelist, blacklist, and script‑based routing rules with implementation details.

JavaEdge
JavaEdge
JavaEdge
Mastering Service Routing: Strategies, Rules, and Real-World Examples

Service routing selects appropriate service nodes for a consumer based on specific requirements, especially when services are deployed across multiple IDC groups.

Typical Scenarios

Grouped calls – route requests to a specific IDC group.

Gray release – pre‑release to a subset of nodes before full rollout.

Traffic switching – redirect traffic from a failed data center to a healthy one.

Read/write separation – route read‑heavy methods to read‑only nodes and write‑heavy methods to write nodes.

Condition‑Based Routing Rules

Routing rules are expressed as condition expressions. The left side matches consumer criteria; the right side filters providers.

condition://0.0.0.0/dubbo.test.interfaces.TestService?category=routers&dynamic=true&priority=2&enabled=true&rule="host=10.20.153.10=>host=10.20.153.11"

Examples: => host != 172.22.3.91 Exclude a specific provider. host != 10.20.153.10,10.20.153.11 => Whitelist the listed consumers. host = 10.20.153.10,10.20.153.11 => Blacklist the listed consumers. host = 172.22.3.* => host = 172.22.3.* IDC isolation – only same‑subnet consumers can call same‑subnet providers.

method = find*,list*,get*,is* => host =172.22.3.94,172.22.3.95
method != find*,list*,get*,is* => host =172.22.3.97,172.22.3.98

Read/write separation based on method name patterns.

Script‑Based Routing

Rules can be defined with scripts (JavaScript, Groovy, etc.). The rule URL contains the script source encoded.

script://0.0.0.0/com.foo.BarService?category=routers&dynamic=false&rule="(function route(invokers){...})(invokers)"

Concrete JavaScript example that only allows consumer IP 10.20.153.10:

function route(invokers){
  var result = new java.util.ArrayList(invokers.size());
  for (var i = 0; i < invokers.size(); i++) {
    if ("10.20.153.10".equals(invokers.get(i).getUrl().getHost())) {
      result.add(invokers.get(i));
    }
  }
  return result;
}(invokers);

Rule Storage and Distribution

Routing rules can be stored in three ways. The evaluation order is:

Local configuration – consumer reads a static file on its own machine.

Dynamic push – an operator updates rules via a governance console; the updated rule is pushed to consumers in real time.

Configuration‑center management – all consumers fetch the same rule set from a central store.

Priority: local configuration > dynamic push > configuration‑center.

Conclusion

Service routing provides fine‑grained control for grouped invocation, gray release, traffic switching, read/write separation, black/white lists, and IDC isolation. Small deployments may use simple local rules, but as the system scales across multiple data centers, centralizing rules in a configuration center and using dynamic pushes improves availability and manageability.

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.

Microservicesload balancinggray releaseservice routingRead-Write Separationcondition routing
JavaEdge
Written by

JavaEdge

First‑line development experience at multiple leading tech firms; now a software architect at a Shanghai state‑owned enterprise and founder of Programming Yanxuan. Nearly 300k followers online; expertise in distributed system design, AIGC application development, and quantitative finance investing.

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.