We think there is an issue with the Session Persistence (Source IP Affinity) or Health Probe failures for the other server.
- By default, Azure Load Balancer uses a five-tuple hash (Source IP, Source Port, Destination IP, Destination Port, Protocol) to distribute traffic. This generally provides good distribution across available healthy instances.
- If you are testing from a single machine or a single external IP address, this would explain why you always hit the same server (For your case, the second one).
Go to your Load balancer > Settings > Load balancing rule > Session persistence > If it's set to anything other than None, change it to None (Default) > Save.
Note: For Basic SKU load balancers, the only session persistence option is Client IP. For Standard SKU, you have more options, but disabling it is the key here.
- The load balancer only sends traffic to backend instances that are reported as healthy by the configured health probe. If your first VM is unhealthy, traffic will be directed only to the second one if it's healthy.
Go to your Load balancer > Monitoring > Backend health > select your BP > please verify the health status of each instance in the backend pool > The instances should be Healthy.
- If one is unhealthy, troubleshoot the health probe configuration and ensure the application on that VM is running and responding correctly on the configured health probe port and path.
- Once you've verified session persistence is off and both backend VMs are healthy, you need a way to see which server is receiving the request.
On your first VM, modify the web page or API endpoint response to include something like "Response from Server 1" and for your second VM, modify the response to include "Response from Server 2" and access the load balancer public IP address or DNS name multiple times, and you should observe the response alternating between "Response from Server 1" and "Response from Server 2", indicating traffic is being distributed.
For your reference: Troubleshoot Azure Load Balancer backend traffic responses
Configure the distribution mode for Azure Load Balancer
Kindly let us know if the above helps or you need further assistance on this issue.