Why and When to use Azure Functions

Why and When to use Azure Functions
Azure functions and lambda functions are two new serverless technologies that are growing faster than anything else in the cloud development. You can see more and more azure functions applications are being developed every day and there is a fair reason for that. If you are new to Azure functions, I highly recommend reading What is Azure functions.
Azure Functions
When architecting a new cloud software or applications, one of the key decisions architects and developers must make is a way to connect to the backend services, running backend tasks, and background processing, and even some simple tasks such as scheduling and sending emails without affecting the main application processing. This is where azure functions app can come handy and useful.
This article focuses on deciding when and why you should use Azure functions instead of Web API and other services.
Before we start with when and why Azure functions, let us try to understand key characteristics of Azure functions. 
  1. Azure functions are language independent. Azure functions is a piece of code that is written to do a specific tasks. Azure functions is platform and language agnostic. You can write an Azure functions in one of the popular programming languages including C#, Java, JavaScript, TypeScript, and Python. You can deploy and execute Azure functions on any platform that can run .NET Core. 
  2. Azure functions are scalable. Azure functions uses compute-on-demand, which is scalable by design. When demand of execution increases, more resources are allocated automatically to the service and when requests fall, all extra resources and application instances drop off automatically. 
  3. Azure functions are lightweight and serverless. An Azure functions app is designed to a specific task and hence it is lightweight by design. Azure functions are serverless and do not require any Web servers or virtual machines to deploy and run.
  4. Azure functions are platform agnostic and run in their own process and environment. You can deploy Azure functions in any kind of configurations including Linux, Windows, or containers but Azure functions are available and can be consumed from any applications as long as they have access to the function.
  5. Azure functions are easier to write and deploy. Because of the nature of the Azure functions, they are easy to code, test, debug, and deploy. You don’t need a large team of developers to do that. A single developer can do everything.
  6. Azure functions are fast to execute because there is no large application, startup time, initialization, and other events fired before the code is executed. 
  7. Azure functions’ execution is triggered when an event is fired. Azure functions setup provides dozens of triggers that can be configured when an azure functions is executed. 
  8. Azure function can be built, tested, and deployed in Azure portal using a browser.
  9. Azure functions are independent. Azure functions are easy to upgrade and doesn’t affect other parts of a website or other applications.
  10. Azure functions use industry standard and can communicate with other APIs, databases, and libraries. This makes Azure functions more accessible in cloud native applications. 
  11. Azure functions can be cost effective because if their nature of running on demand.
When to use Azure Functions?
Azure functions service is a lightweight and serverless compute service that has its own use. You can’t replace a large website with Azure functions.
Here are some of the use cases of Azure functions: 
  • Scheduled Tasks
  • Reminders and Notifications
  • Lightweight Web API
  • Sending background emails
  • Running background backup tasks
  • Doing backend calculations
Azure functions are best suited for smaller apps have events that can work independently of other websites. Some of the common azure functions are sending emails, starting backup, order processing, task scheduling such as database cleanup, sending notifications, messages, and IoT data processing.
Let’s say, you have to send a birthday email to your customers. You’re an ASP.NET web developer. Instead of building a website in ASP.NET, deploy and hosting it on IIS, just for one feature, you can simply write an azure function and put your email login in the function and deploy it on azure cloud. The azure functions will direct connect to your data source, get your customers emails, and send them an email on a scheduled date and time.
Azure functions are best suited for smaller apps have events that can work independently of other websites. Some of the common azure functions are sending emails, starting backup, order processing, task scheduling such as database cleanup, sending notifications, messages, and IoT data processing.
When not to use Azure Functions?
Azure functions are not for everything. Not all applications should be using Azure functions apps. As I mentioned earlier, Azure functions uses triggers and once an event is triggered, the task will be executed in the background. 
  1. Azure functions are not a replacement of Web APIs. If your web applications use Web APIs as middleware to bunch of data and business logic related tasks. 
  2. Unlike Web API or services, Azure Functions are not designed to multiple tasks. An Azure functions app should be designed to do one task only.
  3. Azure functions are not designed to work in tightly coupled systems that are dependent on other parts of application. 
  4. Azure functions are not for front-end applications where data is being accessed and saved back and forth in the backend databases. 
  5. Azure functions should not have too much complex logic in the function code. 
  6. Azure functions are compute-on-demand. Replacing an API with bunch of Azure functions apps may increase your cost of development, maintenance, and compute. 
To learn more about Azure functions and how create and execute Azure functions, check out: What is Azure Functions

Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.