Scott Watermasysk

Still Learning to Code

Multiple Work Roles on Azure

One of the early Windows Azure features that really excited my was the worker role functionality.

If you are not familiar with work roles they are basically a very simple way to do back ground processing when hosting an application on Azure.

Here is a worker role skeleton:


public class WorkerRole : RoleEntryPoint
{
    public override void Start()
    {
        while(true)    
        {
            //Do work here
        }
    }
    
    public override RoleStatus GetHealthStatus()
    {
        return RoleStatus.Healthy;
    }
}

In most case, your work role is going to simply process messages added to a queue. This has a couple great benefits:

  1. It is drop dead simple.
  2. Provides a structured path to move heavy processing out of your web application and does not require managing your own back ground threads.
  3. Since queues (and all of Azure storage as well SDS) are REST enabled, you can easily push tasks to a worker role from just about anywhere (Azure web application and existing applications)

However, as of today, you can only have a single worker role (although you can have multiple instances) associated with an Azure project. I am really hoping this is changed before RTM since working around it is pretty ugly.

  1. Multiple threads – you could create multiple threads within a single worker role. This is very easy to do, but will be very hard to scale since all of your threads will be treated as equals. There are some other things you could do to control this, but it just gets more complicated and uglier with each attempt.
  2. Additional Role Projects – you can today add multiple roles to a single solution file. You can then configure multiple start up projects which gets you the necessary functionality but has two major issues.
    1. Deployment – You will now have to do multiple deployments. There maybe times when your additional work roles are out of sync with your web application and vice versa (in addition, the current CPT limits you to one hosted project, so there is no way to build an application today using this model).
    2. Duplicate configuration – you will now be forced to manage multiple configuration settings. This is not rocket science, but something that will likely catch you off guard at some point.

Overall, I love this functionality and it will simplify (and promote) building more loosely coupled message driven applications…which is a really good thing. However, without support for multiple roles it is going to be severely crippled. I know the Azure team is definitely listening, so hopefully this is something we will see supported very soon.