WebJobs and Function Apps, or Azure Functions, are both services in Azure to run triggered or scheduled tasks. I have worked on setting up WebJobs before and then started hearing/reading about these Azure Functions in various blog posts and meetups. Between the information from these sources and recently studying for the Developing Microsoft Azure Solutions exam made me interested in a comparison of the two services and cases where one solution may be preferred over the other.
In this post I make an assumption on basic knowledge of creating Web Apps and navigating the Azure Portal.
Cost and Storage
One of the first things when suggesting an implementation, other than “How long will it take?”, is “How much will it cost?”.
Creating a Web Job is free as long as you have an existing App Service Plan. Running web jobs does consume resources so you will need to keep track of the usage and scale your service plan up or out accordingly.
Function Apps can use an App Service Plan or a Consumption Plan. You can see the details of pricing on the pricing page but it allows you to only pay for resources while the app is running.
One additional cost of selecting a consumption plan is a storage account. You can use an existing account or one will be created by default when the Function App is created and pricing is handled separately from the Function app.
The consumption plan also includes a free grant of the first 400,00 GB/s of execution and 1 million executions. So depending on the execution time of your code all you will pay for is storage.
WebJobs are a related to an App Service and can be deployed along with the web app they are paired with or uploaded to the Azure Portal as a zip file. For a C# console app this would be the web deploy package. You can have multiple WebJobs in a single App Service.
WebJobs can be run continuously, triggered (for example as a webhook) or set to run on a schedule. The schedule for a WebJob is set in the portal when uploading the zip file or in a settings.job file in the project. The schedule is set using a cron expression.
Function Apps are their own resource in Azure listed under App Services.
For a small side track – in the screenshot below you will notice that both the Function App and Web app are assigned to a different App Service Plan. Didn’t I just make the point previously that Function Apps used a Consumption plan and not an App Service plan?
Going into the App Service Plan you will notice that this plan’s Pricing Tier is set to Consumption where the App Service plan that my Web app is tied to is set to Free.
Function Apps have a unique feature that you can edit the code directly in the browser. When starting up a Function App you are given various ways to create the application – starting from a pre-made or blank template, starting from source control or downloading a publish profile to deploy from Visual Studio.
Both WebJobs and Function Apps have been integrated with other Azure and 3rd party services. Function Apps are built on top of WebJobs so any triggers that WebJobs support Function Apps will, too. For example you can have a WebJob or Function App trigger based on actions in an Azure DocumentDB, Azure Storage, Twilio, Event Hubs and many more.
One point to consider when making a decision between Function Apps and a WebJob is that Function Apps have some limitations on time and memory usage. Function Apps apply a 1.5GB max memory and a 5 minute max execution time. Like many things this will probably change over time but for now it is something that requires consideration.
Now that we have gone through and compared some of the features of each service, when would you consider using each one? Outside a couple requirements it really is dependent on the project and your preference.
Consider using WebJobs when:
- Long running task
- High resource consumption tasks
- You have a Web App that is closely related to the task you need completed
- This is where your skill set lies
Consider using a Function App when:
- Short running tasks
- Low resource consumption tasks
- The task is not closely related to an existing application hosted in your Azure account
- You want the in browser editing capabilities
These are just my opinions – every project is different so use your knowledge of the project and requirements to make the best decision for your project.
One of the challenges I have made for myself at work is, over the next few months I plan to take a look at some of our services and WebJobs that are existing and see if there are any benefits to switching to a Function App.