This blog is an abstraction from the episode “Building Intelligent Serverless Applications” at MSIgnite. This episode was covered by Colby Tresness– Program Manager-Azure Functions and Asavari Tayal– Program Manager, Azure Functions.
History of Cloud Deployment
Before the introduction of cloud computing, an organization maintained every form of data storage on-premise. This methodology involved various risk contingencies like;
- Maintaining servers and storage
- Separate server administrators to maintain the servers
Therefore, to overcome these issues, Cloud computing was introduced. As a result, separate data centres maintain the data of the user for a small subscription fee. Over time, Cloud computing evolved in a dynamic way as follows;
IaaS: Maintains the logical infrastructure rather than the physical infrastructure where the user must only consider some logical requirements like how to deploy the code, how many VM’s required or so.
PaaS (Platform as a Service): In this model, a user can think less of the infrastructure as the service provider will facilitate the requirements of the user upon request e.g. Azure App Service.
Serverless: User can just deploy the code and Azure will take care of the rest of the activities like scaling and also resource pooling.
Definition to Serverless Computing can be easily fragmented into three pieces;
- Abstraction of servers: Developer can just focus on code and business logic without having to worry about infrastructure management
- Event-driven scalability: Dynamic scaling of events on Azure
- Pay-per-use: Allows you to pay only for the serverless components you use. Typically based on code execution time and also the memory used
The ecosystem of Azure serverless system can be easily classified as mentioned in the image.
Overview of Azure Functions
Azure functions are based on some of the core concepts as mentioned below.
What is Intelligent Application?
An intelligent application is the one which takes advantage of machine learning or artificial intelligence in some form. Cortana (Microsoft speech recognition) software is an example which is completely built on AI and machine learning. Even the recently updated Microsoft PowerPoint can be taken as a small-scale example wherein the design tab, the design option can visually enhance any added image or chart on the slide by formatting it with the user’s idea.
How can Azure help with this?
Azure can associate with the process by making use of cognitive service API’s. Any available service calls the API to make use of them. Therefore, Azure logic apps and functions come into the picture where they make use of these API’s to build powerful intelligent serverless applications.
Demo: Building an application out of the box using logic apps
This demo focus on setting up an application using Azure Logic Apps which will be linked to a ticketing system of an organization to parse the incoming tickets based on the sentiments of the customer i.e. satisfied or not. The next step will revolve sending a notification to the organization through a communication channel (Microsoft Teams) on basis of the priority of the sentiments received (<0.5- High priority case; >0.5- Low priority case).
So, the Logic App Designer for engraving with other services will be as specified in the below image.
Step 1: Create a Ticket
Logic App establishes the connection to the respective organization. The user must only give some information like “interval”, in this case, to define at what time each ticket should arrive.
Step 2: Detect Sentiment
Makes a call out to the Cognitive service Text Analytics API to convert the text format ticket received from the previous step into sentiments.
Step 3: Convert the string to float
Specify a condition to change the received string to float value between 0 and 1(if score<0.5- Negative feedback and if score>0.5- Positive feedback). If the user is upset, then it will be considered as a high priority case or else low priority case based on the ticket id.
Step 4: Integrate with a communication channel
Now integrate it with communication channel by giving the connection information and also specify to which channel the notification should arrive in Microsoft Teams. Meanwhile, any ticket received will be maintained in the activity log i.e. run history in the Azure platform for the user to monitor and will also be parallelly received in the communication channel.
Benefits of Serverless
- Serverless just allows you to focus on your business problem without having to worry about the underlying architecture
- Automatic allocation of resources for the user application on basis of its requirement
- Serverless computing offers higher efficiency by providing better service stability
- Much more flexible
Adding Custom intelligence to your application
- To clarify, consider a scenario where customers in a cellular company are on the verge of moving on to another service provider due to the lack of service by them. As a result, the company wants to build an intelligent application where they can detect any customer before they leave and also urge them to stay on their network.
- Here Machine learning can provide a dynamic solution. In general use case, Machine Learning Algorithm follows the steps;
- Find dataset relevant to the problem
- Format it according to your ML algorithm
- Find a statistical algorithm relevant to the ML training process (use the accurate one for better result)
- Train and test iteratively to find the best model
- Once you train the model, use it to produce predictions for any incoming input
In conclusion, any shifting customer can be detected.
Azure Function now supports Python!!! Some of its supporting compatibility includes;
- Develop using Python 3.6 on the functions v2 runtime
- Publish to the Serverless hosting platform on Linux in Azure
- Build, Test, Debug, and also publish using Visual Studio code and Azure Functions Core Tools (CLI)
Demo: Python in Azure Function
Now let us assume the execution of demo in Azure Functions extension for VS code. The first step will be to create a project in an empty directory which lead to the generation of a Function project (equivalent to Function app in Azure). For Python Function project, Visual Studio creates several features for us e.g. requirement.txt to specify the python dependencies.
The next step will involve creating a function in the project and also specify the trigger templates e.g. HTTP trigger. The created project will comprise of two important files.
Function.json– Contains information about the data source that the function needs to bind.
__init__.py– Holds the Python script. The logic mentioned in the below picture will look for a name parameter in the query string and prints the output.
Now when we run the code, a local host endpoint will be generated which triggers the Function. Finally, the assigned name in the query string will be displayed as output.
Demo: Predicting customer churn
This demo involves training a model to write a predict script and package it up with Azure functions to deploy it to the cloud.
The initial step will be to identify an algorithm to train the model (based on Machine Learning) derived from the dataset and also the trained model will be checked for accuracy on how it satisfies the application requirement.
Now the inputs (CSV format) received from the blob storage of the user application will be consumed by the Azure functions to run against the model created. Consequently, this will produce an output prediction of whether a customer would churn or not.
In visual studio, the project created will comprise of a user-defined function followed by a function script which uses Azure functions cognitive service API to convert the input of the user statements into sentiments and similarly to predict whether the customer would churn or not. Now upon executing the code, the function will derive any incoming event in the blob and process the sentiments to derive the output.
Function hosting options
The biggest advantage of Azure Functions 2.0 is that Azure core tools run locally on any platform like Linux, iOS, and Windows. A user can develop an application locally or can just push to Azure for hosting. Different methods of hosting a function in Azure is as mentioned in the image.
In conclusion, this blog gives an overview of how serverless makes it easy for the user to overcome the difficulties involved in machine learning like data ingestion, processing, model training, and also model updates to prediction. Furthermore, it explains the various benefits involved in creating an intelligent application through Azure with some demos for a better understanding of the audience.
You can watch this session here.