6
votes

Can I have a Web Role and a Worker role run on the same instance, or do I have to obtain 2 separate hosting instances and pay twice the amount I would otherwise?

I have a WCF Web API that I want to host on Azure. I also have a Worker Role that listens to a Queue in Azure Storage. Every time a message is added to the Queue, it will obtain that and run a small task depending on the message.

I was wondering if I can just run these two on the same instance or not.

2

2 Answers

4
votes

"Worker Role" and "Web Role" are just simple templates for "Windows Server 2008 with IIS running" and "Windows Server 2008 without IIS running." The key is that a "role" is a definition of a Windows Server virtual machine. For each "role" you have one or more instances.

In Windows Azure, both role types have the ability to install software, modify registry settings, etc. in either a startup script or OnStart() handler, and both let you run code in the Run() method.

In your case, you can run your WCF Web Service in a Web Role, and then in your Run() method (in the same role), kick off a process that listens to queue messages posted by your WCF web services. No need to have a new role.

Now: Once you get into high-volume situations, you might want to split your code into separate roles, so you can scale them independently (both in VM size and VM quantity).

I posted another answer about this here.

0
votes

It completely depends on your requirement. You can simply have a Worker Role that exposes an external endpoint as described here and expose a WCF Service. You can also have Web Role that is a WCF Service and spin up a background thread that checks the queue. What is the Worker doing with the message? What process is performed? That also has an impact on the solution.

A key thing you need to consider is whether the scaling requirement between your WCF Service and the queue retrieving tasks are the same. If they are a single role should be good enough to start with.