Combine WorkerRole and WebRole Windows Azure

Sometimes is cost efficient to combine a WebRole and WorkerRole. In this way you use the complete capacity of the VM/Server, without the need of extra instances.

Assume this scenario. You got a WebRole with 2 Websites and a WorkerRole. But now the WorkerRole could do with a smaller VM. Of course you can chose a smaller VM, but what if you already are using the smallest instance (XS)? And besides that the WebRole with 2 Websites also not using the complete capacity of the VM.


In this case it looks interesting to combine the two roles.


This combination can be done quite simple, by moving the WorkerRole logic to the WebRole. This can be done by adding the method Run() to WebRole.cs.

Remark: of course you also have to move the specific settings from the app.config or Role configuration from the WorkerRole to the WebRole web.config or Role configuration.

public override void Run()
Trace.WriteLine(“WorkerRole entry point called”, “Information”
while (true
       <own logic>

Trace.WriteLine(“Working”, “Information”

Here a more detailed example. 


In the Local Development Emulator you will see the actual Traces from the Roles. Meanwhile the website is opened in a browser and fully functional. Of course as a user you do not notice that a process is running in the background. If you do, then you need to splits it again Winking smile.


The other way around is also possible. You can add the WebRole logic to a WorkerRole. But then logic for starting a Website is necessary. The first is the simplest one.

Leave a Reply