When developing a web app that runs in Azure, you may need to create a background service to do some processing. In the on-prem world, a Windows Service or Scheduled Task that kicks-off a console app could do the trick, but how does this work in the Azure world where you don’t have a ‘server’ to deploy services to? This article discusses two options that work well for this: Azure Functions and Azure Webjobs—code-first options for writing background services in Azure.
First, the similarities:
Both are fully supported by Visual Studio. You can develop and test locally before deploying your solutions to Azure (and incurring the costs associated with that deployment). Both are fantastic options for any background processing tasks (image processing, nightly notifications, overnight order processing), or any task you want to run on a schedule.
The following table highlights the major differences between the two. Most of the time, either option will allow you to accomplish the same goal, but Azure Functions allow for more flexibility with architectural design.
Functions | Webjobs with Webjobs SDK | |
Serverless App model with automatic scaling | ✔︎ | |
Develop and test in browser | ✔︎ | |
Pay-per-use pricing | ✔︎ | |
Integration with Logic Apps | ✔︎ | |
Trigger events | Timer Azure Storage queues and blobs Azure Service Bus queues and topics Axure Cosmos DB Azure Event Hubs HTTP/Webhook (GitHub, Slack) Azure Event Grid |
Timer Azure Storage queues and blobs Azure Service Bus queues and topics Axure Cosmos DB Azure Event Hubs File system |
Supported Languages | C# F# JavaScript Java Python |
C#1 |
Package managers | NPM and NuGet | NuGet2 |
1WebJobs (without the WebJobs SDK) supports C#, Java, JavaScript, Bash, .cmd, .bat, PowerShell, PHP, TypeScript, Python, and more. This is not a comprehensive list. A WebJob can run any program or script that can run in the App Service sandbox.
2WebJobs (without the WebJobs SDK) supports NPM and NuGet.
Azure Functions
One of the first things to consider with Functions is the pricing plan you’ll be deploying to. You have two choices with Functions, the Consumption Plan or the App Service Plan.
Consumption Plan
Under this plan, you only pay for the time your Functions run. This can be ideal if you know the number of times your Function will run. For example, if you send out email notifications, or do overnight processing, you can easily estimate your total usage and cost this way. If you have Functions you can’t estimate the usage of, but you don’t want to incur any large costs, the better option is to look at the App Service Plan.
Azure provides a free grant for Functions under this plan. Every month, you get 400,000 GB-s (gigabyte seconds) of execution time and 1 million executions for free. This is a great offer to allow you to determine if Functions can suit your needs.
App Service Plan
Under this plan, your Function runs under the same plan Azure uses for web apps, api apps, and mobile apps. If you have one of these three deployed, it might make sense to use the App Service Plan to deploy your Functions to, since your platform costs won’t increase. Another advantage of running under an App Service Plan is your functions now can run up to 30 minutes (or unlimited with configuration changes).
Azure Webjobs
One requirement of Azure Webjobs is they need to run under the context of an Azure App Service (web app). Azure Webjobs don’t have a maximum run time. Like Functions, however, they do share their memory & CPU with the web app. If your Webjob uses large amounts of memory or CPU your web app performance will degrade.
Some factors you might want to consider in choosing one:
Webjobs
Functions
Azure Functions are built on top of the Web Jobs SDK, so they can do all that Webjobs can do and more. Microsoft recommends Azure Functions for all new development (and I would agree). Version 2 of Functions eliminated many of the limitations of the first version. In particular, allowing Functions to run longer than ten minutes is a huge advantage. Finally, if your organization has any additional questions around Azure Functions, please don’t hesitate to reach out to us. We’d love to help you get started.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.