Introduction to Azure serverless with Azure Functions, Logic Apps and Azure Event Grid
In this blog post I’ll introduce you to what is serverless and then what services in Azure provide serverless capabilities. First let’s define what is serverless.
What is the definition of Serverless
- It’s an abstraction of servers. This doesn’t mean there are no servers, there are still servers behind the scenes but this means you don’t need to worry about optimizing which OS to run, about OS patching, etc. You also don’t need to worry about optimizing utilization and scaling up and down for demand. Think of it as less server more code.
- It’s an event driven process. You simple tell Azure how or when to run your code. This could be based on a schedule or when a new customer is added to Salesforce, or when items are added to a queue, to a table storage, etc.
- It’s micro-billing. This means you’re only charged for your usage.
The benefits of serverless
- Reduced DevOps — You can dynamically and elastically scale to meet demand.
- Focus on Business Logic — Allows you as the developer to focus on your business logic and everything else is taken cared of for you. No need to provision resources and wait on ITOPS. In some cases you can design and develop your serverless code offline.
- Faster Time to Market — By focusing on your business logic and features, you’re able to drastically increase time to market.
Let’s now look at three Azure services that provide serverless capabilities.
1. Azure Functions
Azure Functions is an event driven, compute-on-demand experience. You can easily and quickly build the apps you need using simple serverless functions that scale and meet demand and you only pay for your usage.
Azure Functions allows you to bind into services. This means you can integrate Azure Functions into Cosmos DB, Logic Apps, queues, table storage, on premise and so much more.
With Azure Functions you simply provide your code and then let Azure take care of the rest…meaning that when an event happens, Azure will automatically take care of everything to run that code at scale.
2. Logic App Service
Azure Logic Apps are built around the idea of events, triggers and workflows. When you think about building microservices, there are a lot of moving parts to manage. Azure Logic Apps lets you stitch them all together much more easily and provides you with a central place to build and manage all of your event-driven services.
Logic Apps are a fully managed iPaaS (integration Platform as a Service) that provide serverless workflows that allow developers to easily integrate data with their apps instead of writing complex glue code between disparate systems. This allows you to orchestrate and connect the serverless functions and APIs of your applications.
Benefits of Logic Apps
1. You can quickly tap into the power of the cloud and fire events from other services.
2. You can orchestrate almost anything:
- Run mission-critical, complex integration scenarios with ease
- Connect on-premises, hybrid and cloud applications
- Position for future with API centric connectivity
- Easily connect custom on-premises applications to the cloud
At the time of this post there are over 200 connectors available out of the box. Connectors reduce integration challenges and enable you to quickly and easily connect apps, data and devices anywhere.
Creating a Logic App
The following is a sample Logic App. As you can see you simply string together Connectors, Triggers, Conditions and Actions to form the basis of your Logic App. When your Logic App is running you can monitor and inspect each run iteration and see what data came in and the path it took through the Logic App.
In summary Logic Apps is the workflow engine built for the cloud with cloud scale, massive compute and high availability built in.
3. Azure Event Grid
Finally there is Azure Event Grid which is a messaging service built to easily build application with event-based architectures. You simply select the Azure resource you would like to subscribe to, and give the event handler or webhook endpoint to send the event to. Event Grid also has built-in support for events coming from other Azure services, like resource groups, subscriptions, storage blobs, and event hubs.
Topics and Subscriptions
Event Grid is similar to Azure Service Bus in that a Topic is an endpoint that receives messages, and a Subscription is used to receive messages through the Topic that will be handled by a message listener. These concepts are basically the same, but there are some differences in how they work. Event Grid it uses a concept of events instead of messages since it’s an event-based messaging system, and because Event Grid is based on events, it lends itself nicely to microservice architectures using serverless compute options like Azure Functions and Logic Apps in addition to other implementations.
There are also more differences between Azure Event Grid and other message queue services. The capabilities of Azure Event Grid are centered around speed, scale, breadth, and low cost. Rather than being a general / generic messaging service, Azure Event Grid is built specifically for Serverless architectures.
Currently Azure Event Grid has built in support for the following event publishers:
- Event Hubs
- IoT Hubs
- Blog Storage
- Custom Topics
- Azure Subscriptions (management operations)
- Resource Groups (management operations)
Currently the following Azure services have built-in handler support for Event Grid:
- Azure Functions
- Logic Apps
- Event Hubs
- Azure Automation
- Microsoft Flow
If using Azure Functions as your handler, use the Event Grid trigger over the generic HTTP trigger as it automatically validates Event Grid Function triggers.
Azure Event Grid is built specifically for Serverless architectures.
Event Grid Architectures
Azure Event Grid is designed to be used in microservices and event based architectures. It can be used in a serverless application to connect data sources and event handlers. In an ops automation scenario you can notify Azure Automation when virtual machines are created, or when a SQL database is spun up. Finally you can use Event grid to connect your application with other services. The possibilities are really limited by your imagination.
As you can see all three services provide a different component to the serverless story and each of them integrate nicely with each other. They each allow you to think less about the server and more about your code and you only pay for your usage. The best way to learn about these Azure serverless offerings is to create a free Azure account and try it out yourself.
Attribution: This post uses one or more graphics from the official Azure Event Grid documentation, such as diagrams.
Originally published at theflyingmaverick.com on February 2, 2018.