Java gRPC - Single Channel with multiple DNS of same backend

70 views
Skip to first unread message

Abhinav Kinshuk

unread,
May 27, 2025, 2:06:26 AMMay 27
to grpc.io

Different instances of the same backend I want to use in my gRPC Channel are hosted in different AWS regions with different DNS. I want to pass in all these different DNS at the time of Channel creation, probably something like this -

```
ManagedChannelBuilder.forTarget("multi-endpoint://dns1.com;dns2.com;dns3.com")
```

Then, I want to write an implementation of the NameResolver interface that gRPC provides, to do the name resolution individually for the three DNS. However, it works only if the serviceAuthority is same across all the DNS.

My questions are -

  1. Should I even be creating a single Channel with multiple DNS? Is it anti-pattern?
  2. Is it possible to create a single Channel with multiple DNS and have it work when serviceAuthorities are different?
  3. Should I create multiple Channels, one for each DNS?

Thanks,
Abhinav.

Kannan Jayaprakasam

unread,
May 28, 2025, 2:53:23 AMMay 28
to grpc.io
Firstly to make sure we use the same terminology, what you pass to the ManagedChannelBuilder.forTarget is not the DNS address but the domain name or the hostname of the target you are connecting to. The hostname starts with a DNS resolution scheme that identifies whether an in-built or a custom name resolver gets used, and you register a custom name resolver with the name resolver registry (guide). gRPC target urls follow the format for RFC-3986 (as explained in the above guide also) which allows the service authority to be specified between the 2nd and the 3rd slashes after the URI scheme. 
About your questions
1. It can be an anti-pattern because the gRPC allows specifying load balancing policy in the service config encoded as Json in the txt record of the name resolution. In-built load balancers such as pick first or round-robin are designed to work with a single load balancing policy for the channel. It may not be an issue if you don't have the txt records specify any load balancing policy, so the channel uses the default configuration for load balancing.
2. It is possible, by omitting specifying the service authority in the target URI but have your custom name resolver handle contacting one or more of the service authorities. However as the custom name resolution guide explains, you may need custom load balancing policy to deal with service configs from different name resolvers.
3. Creating multiple channels one for each DNS is the normal method anyway.

Reply all
Reply to author
Forward
0 new messages