04 Feb 2009 @ 4:29 PM 
 

Web Role vs Worker Role

 

As of the date of this post, when you are working with Windows Azure Services, you get the option to create either a web role or a worker role (or both) for your Cloud Services project. But what are these roles exactly and what do they do?

Well you can think of each role instance as its own project. I tend to liken the two roles to existing Visual Studio project templates.

The Web Role is similar to a ‘Web Application’ – it has aspx pages and code behinds, but can also server anything that uses the http protocol, such as a WCF service using basicHttpBinding. The Web Role is driven by UI – the user interacts with a web page or service and this causes some processing to happen. As far as I can tell, the http pipeline is very similar to standard ASP.NET requests. Just think of it as a good old ASP.NET web application.

The Worker Role is similar to a windows service. It starts up and is running all the time. Instead of a timer, it uses a simple while(true) loop and a sleep statement. When it ‘ticks’ it performs some kind of maintenance work. This is great for background processing.

What the worker is working on is up to you of course, but usually it needs some data to work with. This data can come from a number of places. For example, the AzureServicesKit has examples that show you how to communicate between a worker and a web role via the use of a queue. The idea here is that the worker role doesn’t care how stuff got into the queue: it just does its job of processing items in the queue. It is the web role that is user driven and causes data to go into the queue. The web role can then monitor the queue (via some nicely placed Ajax) and show the results when they have been processed.

So you might think: I’ll always need a web role if I have a worker role. However, this is not true.

Think for a second about Live Mesh. Here you have a folder of all your holiday photos and you’ve modified the actual photos with metadata containing the name of the town or city you took the photo. Live Mesh is built on the same services as the rest of Azure, so communicating between the two is quite easy. You could potentially create a Cloud Service with just a worker role that monitors a particular Live Mesh folder for photos, and when a new one is added, it checks for that metadata with the city name, and inserts latitude/longitude coordinates as additional metadata.

Lets run with that example for a moment. Imagine that the Live Mesh folder is actually a shared folder with thousands of people having access to it (you can do that in Mesh). People are uploading their photos from cities all around the world. Your single worker role can’t keep up with the demand! That’s where Azure steps up: this is what it was truly built for. You can very easily add another instance of your Worker Role. All of a sudden, your processing time is halved!

So there you go. Currently there is a limitation of 2 instances per role. And you can only have one worker role and one web role in your solution at the most. This will seem very restricting once you start to really get into Azure but I suppose there has to be some limitations while Microsoft builds its datacenters around the world.

Steve Marx stated about a month ago (see the comment at the bottom of that link):

we’re absolutely interested in giving the ability to have multiple worker roles, and multiple web roles, and some other kinds of roles, and direct synchronous communication between them …

He goes on to mention that Microsoft are careful about releasing functionality in a staged manner. I’m predicting that some of the roles we see will more closely match some of the existing projects in Visual Studio, in particular an ‘MVC Web Role’.

Oh before I wrap up, you can also write your worker roles in F# now! Check out the Microsoft site for the download.

 

Technorati Tags: ,,,,
Tags Tags: , , , ,
Categories: Azure
Posted By: Steven Nagy
Last Edit: 10 Feb 2009 @ 06 31 PM

E-mailPermalink
 

Responses to this post » (13 Total)

 
  1. Above The Cloud » Blog Archive » What Is: The Azure Fabric and the Development Fabric said...
    12:04 am - March 23rd, 2009

    [...] When we write our Azure applications locally, there is a simulation of this fabric running on our machines, called the ‘Development Fabric’. This lets us simulate load balancing and multiple nodes for our web and worker roles. [...]

  2. MichaellaS said...
    10:54 am - July 22nd, 2009

    tks for the effort you put in here I appreciate it!

  3. George said...
    10:09 am - November 19th, 2009

    Very usefull, it made the picture clear about each role. Thanks very much.

  4. Steven Nagy said...
    5:02 pm - November 19th, 2009

    No problems. This post could use a do-over now that there’s a bunch more stuff integrated into Visual Studio. I’ll put it on the todo list!

  5. Above The Cloud » Blog Archive » Windows Azure Development Deep Dive: Working With Configuration said...
    10:54 pm - March 7th, 2010

    [...] standard .Net applications. If you have a web role, then you have a web.config. And if you have a worker role, you get an app.config. This allows you to provide configuration information to your role when it [...]

  6. Above The Cloud » Blog Archive » Why do I need more than 1 web role? said...
    10:28 pm - May 9th, 2010

    [...] we continue, I’ll defer you to one of my earlier posts about what exactly a web role is: The Web Role is similar to a ‘Web Application’ – it has [...]

  7. Above The Cloud » Blog Archive » Azure Terminology said...
    1:04 pm - May 16th, 2010

    [...] that you write will run on Windows Azure Compute. Web and worker roles that you write will be hosted on the platform and distributed throughout the data centre based on [...]

  8. All about Azure Storage – Blobs « Alisafri's Blog said...
    9:35 pm - April 2nd, 2011

    [...] case Web or Worker role is [...]

  9. Above The Cloud » Blog Archive » Ten Things You Didn’t Know About Windows Azure said...
    10:11 pm - June 5th, 2011

    [...] talked about web and worker roles quite some time ago. The key premise is the same; web roles are great for hosting websites and [...]

  10. travel insurance|travel insurance usa said...
    1:16 am - October 6th, 2012

    travel insurance|travel insurance usa…

    Above The Cloud » Blog Archive » Web Role vs Worker Role…

  11. cheap mobile app developers manufacturers said...
    7:53 pm - November 7th, 2012

    cheap mobile app developers manufacturers…

    Above The Cloud » Blog Archive » Web Role vs Worker Role…

  12. fresible.com said...
    10:58 am - November 21st, 2012

    fresible.com…

    Above The Cloud » Blog Archive » Web Role vs Worker Role…

  13. Learn Additional Here said...
    1:25 pm - February 6th, 2013

    Learn Additional Here…

    Above The Cloud » Blog Archive » Web Role vs Worker Role…

 

Leave A Comment ...

 

 XHTML:
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
\/ More Options ...
Change Theme...
  • Users » 86
  • Posts/Pages » 64
  • Comments » 180
Change Theme...
  • VoidVoid
  • LifeLife
  • EarthEarth
  • WindWind « Default
  • WaterWater
  • FireFire
  • LiteLight
  • No Child Pages.