What exactly is Serverless?
Azure Functions, Google Cloud Functions, AWS Lambda are some of the popular implementations of serverless computing available out there. But you might wonder what exactly is serverless, doesn’t it require a server?
Yes, it runs on web servers and it does all that a web service (with a provisioned infrastructure of a web server) can do. But in this case, the code to run the web services is written by you and these cloud service providers do the rest of the work for you. That includes spinning up a virtual machine as the base infrastructure to run the web service, managing the operating system, installing the dependencies, running the code to evaluate the requests. This code needs to be in the form of independent functions or modules/classes. Let’s take NodeJs with Azure Functions for example, You need to write a nodejs module containing your logic, so that Azure knows what you want it to do.
If you have come across how micro-services architecture has brought reliability at scale to various tech giants such as NetFlix or Uber, you might be interested in knowing that all of the benefits of such architecture come hand in hand with adopting a serverless architecture.
Let’s try to understand how this works in a quickest way.
Most common way to invoke a Function in AF is to attach a HTTP Trigger to it. Azure gives you an end point and you can configure what HTTP methods you want to support.
A Storage account in your azure (like Amazon S3) is created and used as a repository for your code and configuration files. Everytime a function is invoked by a trigger, Azure will deploy your code in a VM (the compute resource) and have it evaluate the request from the trigger with the function specified. once the outpur is available to the Functions Host, it is given back as the response to that trigger.
There’s a bit more to the story,
- Everytime a function is invoked, Azure will look if that function is already in the runtime, only if it is not in the runtime, Function will be reloaded.
- Azure tries to keep the function in the runtime to avoid a slow responce due to loading time of a function, hence the function and the host VM is available for a few minutes after when the function was last invoked.
- With the increasing number of requests, Azure deploys same function on various machines to make it highly available. This means you need to write stateless functions because there might be more than one instances of your function at any given time.
- Billing: Azure only bills you for the actual execution time for your function. It has its own unit known as GB-Sec, so if your function is consuming 1 GB of memory for 1000 milliseconds in its execution, you will be billed 16 microdollors (Pricing is 0.000016 USD/Gb-Sec).
I hope you try Serverless for your next project.
Here are some more resources if you are looking to get deeper insights:
Explore the great and excellent solutions for processing data, integrating systems with Azure Serverless computing with…www.packtpub.com
With the rise of Cloud deployment, Microsoft provides a solution to easily run small pieces of code in the Cloud with…www.udemy.com
Here’s a bit advanced course on Serverless using Azure:
Explore How to Deploy, Monitor, Debug and Design Scalable Solutions with Azure Serverless Computingwww.packtpub.com