Search code examples
.netdnsamazon-web-servicesload-balancingsystem.net.httpwebrequest

Which IP does .NET HttpWebRequest use if DNS entry is bound to multiple addresses


I'm using a System.Net.HttpWebRequest to hit an API application hosted within AWS behind a load-balancer. The LB has 6 instances, 3 in 2 different AZs. As a result, the DNS entry for the LB has 2 IP Addresses (1 for each AZ).

When I run my C# app, the web requests appear to be balanced perfectly between 3 servers within a single AZ. It's not hitting the 2nd AZ.

It seems to me that the WebRequest object is only ever hitting the 1st IP that is bound to the LB DNS entry, which is why traffic is balanced, but only in a single AZ.

Does that make sense? How do I get the WebRequest to target other IPs bounds to a DNS entry?


Solution

  • HttpWebRequest always uses the first IP address in the list. Route53 returns the IP addresses from a single loadbalancer in a random order which help balance the load across the AZs.