The key differences between Azure Logic Apps and Azure Functions
What's better for your project: Azure Logic Apps or Azure Functions? It's an important question, and one we often face when implementing solutions for our clients. The answer depends on what you’re trying to achieve and the technical skills within your team. Both are great tools for integrating different systems and automating business processes, however, each has unique attributes that situationally can make it a better option over the other.
Here are some benefits, disadvantages and use cases for both Azure Logic Apps and Azure Functions so you can gain a clear overview of each and decide which is the better option for your enterprise or organisation’s projects.
Azure Logic Apps Overview
What are Azure Logic Apps?
Azure Logic Apps is a low-code, cloud-based platform designed to help you integrate apps, data, systems and services across enterprises or organisations. It simplifies the way that you connect legacy, modern, and cutting-edge systems across cloud, on-premises and hybrid environments.
Logic Apps can help you quickly develop highly scalable integration solutions for your enterprise and business-to-business (B2B) scenarios. It uses a visual workflow designer that lets you choose triggers and actions that build to one another to make automating and scheduling tasks, business processes and workflows simple.
What do Azure Logic Apps cost?
There are two key options for pricing which are Consumption (pay-per-use) and Standard (fixed resource). With a Consumption Logic App, pricing depends on the number of actions, the number and type of connectors and any polling triggers. Standard Logic Apps, on the other hand, provide reserved capacity and resources which you’re billed for whether or not you use them. The pricing tiers in the Standard model are based on the amount Virtual CPU and Memory you want to reserve.
Azure Functions Overview
What are Azure Functions?
Azure Functions is an entirely coded service that lets you run and accomplish more complex tasks. It can be run serverless, inside an application service plan, on-premises inside your own datacentre, while managed by Azure Arc or in a Kubernetes cluster.
Azure Functions has been designed to provide compute on-demand services based on predefined triggers or events. It provides readily available blocks of code called functions. These functions allow developers to invoke blocks of code that generate an output to be consumed by the intended application.
It relies on triggers that use input and output bindings to define the information being passed to the function. Azure Functions can be built in various languages like C#, F#, Node.js & TypeScript, Python, Java and PowerShell.
What do Azure Functions cost?
There are multiple pricing options for Functions, including pay-per-usage, standard monthly fees or a hybrid pay-per-usage monthly fee option. The final costs can be based on execution count, or CPU and Memory requirements. How auto-scaling works depends on which hosting plan you’re on; Consumption, Premium or Dedicated.
Use cases for Azure Logic Apps
Benefits of Azure Logic Apps
Azure Logic Apps low-code approach to integration and automation include:
- Proof of concept (POC) mock-ups can be delivered faster.
- Required connectors are built-in and easy to create.
- Accessible JSON templates simplify self-documentation.
- Run history streamlines troubleshooting allowing you to see where something has failed and why.
- Error handling and exceptions are simplified through built-in options.
- Patches and updates aren’t required as it’s cloud-based and serverless.
Azure Logic Apps Use Cases
These benefits make Logic Apps the ideal integration and automation tool for the following tasks, business processes and workloads:
- Connecting one API to a separate system API while transforming data.
- Creating event-based triggers such as files created in blob storage, new messages in Service Bus Queue and new emails in inboxes.
- Running tasks on a timer.
Disadvantages of Azure Logic Apps
However, Azure Logic Apps do come with drawbacks. For example, they can only be run in Azure or Azure Managed Servers and variables are designed at a global level making achieving those within an inside scope difficult. Additionally, complicated actions can be cumbersome to build – this can be overcome by invoking Functions or the updates in Standard Logic Apps which allow multiple workflows inside a single Logic App.
Use cases for Azure Functions
Benefits of Azure Functions
Azure Functions and Azure Logic Apps have been designed to resolve their own niche of problems. While Logic Apps revolve around low-code and prebuilt structures, Functions are full-code and designed to do one thing well — you can have multiple Functions within your Function App, so you’re really only limited by your coding ability.
The functions support multiple coding languages and can be invoked outside of Azure, such as in Power BI, and can be run locally for development purposes, in containers or in Azure.
Azure Functions Use Cases
The level of flexibility that Functions provide make it the ultimate tool if you're looking for feature rich implementations aligned with your systems logic. There are plenty of use case examples for Azure Functions, however, these are common situations where we utilise them:
- Generate authentication tokens.
- Converting a spreadsheet into a csv and vice versa.
- Datatype conversions (metres to miles, kilobytes to megabytes, etc.).
Azure Functions Disadvantages
Complete flexibility — as to be expected — can have its drawbacks too, which, ironically revolve around code. First, you need to know how to do it. Second, you need to scope how much of it you want to do; with functions, you can quite literally do whatever you want which can become time-consuming if projects aren't initially scoped. Third, you'll need to build your own exception and error handling.
In addition to these code-oriented drawbacks, you'll need to handle and pay for your own hosting; certain rates limits exist based on plan types. With all this in mind, with Functions, there's a greater risk of downtime and system failures as cold starts in consumption plans can cause Azure Functions to fail on the first run. Although you can pay more to avoid this.
Azure Logic Apps versus Azure Functions: In-practise comparison
To help paint a clearer picture of how each works we've put together this in-practise comparison. In these examples, you'll see some of our more common scenarios including individual Azure Logic Apps and Functions and a Logic App which invokes a Function.
Example Logic App
Some tasks need to happen on a regular basis, so this example retrieves a list of transactions from your SQL database every day and processes each transaction accordingly.
At a basic level, the Logic App:
- Triggers every day.
- Gets a list of transactions from an SQL table.
- For each transaction:
- Check a state table (Azure Table) to see if this transaction has already been processed.
- If this transaction already exists in the state table, print a message to advise us of this.
- Otherwise, retrieve a GL Code from another SQL table and continue processing.
Here is what the Logic App looks like:
Example Azure Function
A major benefit of Azure Functions is that they’re code-based and as such you can utilise libraries available to you in your coding language. For this example, we take advantage of Python’s hashlib, base64 and hmac libraries to construct the LMv1 authentication token needed for the LogicMonitor API.
At a basic level, the Function:
- Receives the access information in the query parameters.
- Generates a hmac signature using hmac and hashlib.
- Encodes the hmac signature using base64.
- Constructs the full auth header which is returned in the function response.
This function has come in handy not only within Logic Apps, but we’ve also used it in Power BI and when testing in Postman and Insomnia.
Here is what the Integration and Code + Test sections look like in Azure:
Example Logic App with Azure Function
For this example, let’s say that we want to extract the data and specific values from the line items in invoices as they’re emailed to us and send that data to our database.
At a basic level, the Logic App would:
- Trigger on new emails arriving.
- Send the invoice to the Form Analyzer Cognitive Service.
- Send the extracted order info and line items to a database.
- Move the email to an archive folder so it’s not processed again.
In this scenario, we encounter a JSON object from the Form Analyzer which has multiple nested arrays, and we need to access values that are in one of those deeply nested arrays. On top of that, the number of items in that array will vary because we’re analysing an invoice’s line items. With some determination, you can make it work in Logic Apps alone. However, as you build out nested for-each loops and append values to variables, you have to stop and think about how easy it’s going to be for someone else to come in and troubleshoot if your runs start failing and you’re not there to fix it.
In place of a big mess of nested for-each loops, we would deploy a function and invoke it within the Logic App. Here’s what this Logic App might look like:
Notes: This is a simplified Logic App for the purposes of this blog and is not a final product that should be implemented without proper testing and error handling.
What's better Azure Logic Apps or Azure Functions?
We've worked with both Azure Logic Apps and Azure Functions on large (100,000+ messages a day across multiple Logic Apps and Functions) and small-scale (run once per day or month) integration projects and in our opinion the best option really is situational as both have their strengths.
Our general approach and rule of thumb are always to start using Logic Apps where you can, and then utilise Functions for complex actions which are not available in Logic Apps. What we mean by this is simple; use a Logic App component to get started and if you encounter any restraint or difficulty add in a Function to overcome it. Logic Apps are a great orchestrator so even if something is difficult to accomplish in a Logic App, you can use a Function within the Logic App to accomplish that task.
Eager to learn more about how you can utilise both Azure Logic Apps and Azure Functions in your organisation or enterprise's projects but not sure where to begin? As Microsoft Advanced Specialisation and multi-Gold Partners, we've got the knowledge to help set your company up and on its way. If you'd like more information or to chat about your options, please drop us a line.