As far as I know Azure does not have a load balancer for internal services, internal endpoints are not load balanced. But can someone have implemented a "soft" solution, or can advice me some helpful articles to read?

Thx a lot


There are two ways you can handle this: One way with services running in Virtual Machines, and another for services running in web/worker roles.

First: Virtual Machines. If you have your service running in a Virtual Machine, you could take advantage of Azure's external load-balancer to load-balance across multiple virtual machines running in a single service. Traditionally this posed a security issue, as you'd have an external (input) endpoint open to the world and would need to implement your own security accordingly within the VMs themselves (iptables / Windows firewall). There's a brand new feature called ACL'd Endpoints, which let you allow/block access to an external endpoint based on IP ranges. This means any traffic from a cloud service (whether virtual machines or web/worker) could be properly allowed access with a simple configuration call (only via PowerShell today). Here's an excerpt taken from Michael Washam's blog post about this:

$acl = New-AzureAclConfig
Set-AzureAclConfig -AddRule Permit -RemoteSubnet "" -Order 1 -ACL $acl -Description "Just for my deployment"
Get-AzureVM -ServiceName myservice -Name myvm | 
Set-AzureEndpoint -Name restapi -Protocol tcp -PublicPort 8000 -LocalPort 80 -ACL $acl | 

Next: Web/worker. Let's say you're running a private service in a worker role, with several instances. You can enumerate the instances from your caller (e.g. a web role instance), then select one of the ip+port's at random (or round robin, or whatever mechanism you choose). Fairly straightforward, doing something like this (and borrowed from my StackOverflow answer here):

private String GetRandomServiceIP(String roleName, String endPointName)
    var endpoints = RoleEnvironment.Roles[roleName].Instances.Select(i => i.InstanceEndpoints[endPointName]).ToArray();
    var r = new Random(DateTime.Now.Millisecond);
    int ipIndex = r.Next(endpoints.Count());
    return endpoints[ipIndex].IPEndpoint.Address.ToString();
  • If you randomly choose an instance to go, what if one of instances has failed, it will have a chance to take the fault one? And it's without any performance probing, is just completely a random strategy. – iNc0ming Jul 26 '13 at 2:27
  • I gave you an example that gives you everything you need for enumerating internal endpoints on Windows Azure (along with a Virtual Machine LB solution as a bonus). Feel free to modify to make it more robust with performance probing, instance failure detection, etc. – David Makogon Jul 26 '13 at 4:22
  • thanks, I'll have a go, it sounds not that difficult.I need to be careful about the performance impact on probing and failure detection.thanks again! – iNc0ming Jul 26 '13 at 8:12

A software solution to load balancing would be to use a Service Bus queue with the Worker role instance count > 1. Each worker role listens to the queue and processes the messages as they come in. Busy worker roles will obviously have to finish what they are doing before grabbing the next message off the queue and processing it. That way the load is distributed among the worker role instances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.