The cloud computing introduced us to lot of new development and architecture patterns as well as new deployment models. It enabled us to think in terms of Virtual Machines(VMs) or IaaS, then containers, then PaaS and now the Function as a Service(FaaS) or commonly called serverless.
When using cloud services, the developer still needs to think about infrastructure like provisioning of VMs(compute units/network infra etc) and related services like storage (like EBS for AWS VMs). Serverless architecture relieves us of some of these additional configurations and are extremely useful to solve certain use-cases (discussed later).
So what is Serverless computing?
The word serverless is actually a misnomer. Serverless does not mean that no servers are required. It simply means that serverless relieves developers from the additional effort of understanding the underlying infrastructure on which the serverless service is running. So let’s compare it to a PaaS service like SQL DB where you need to configure the VM capacity, ssh details etc for the server and so on. In FaaS, you just need to provision the service with the required code that needs to be executed in the function, rest of the stuff is automatically taken care by the service fabric of the cloud infrastructure. Hence at ease of management the FaaS stands at top of the pyramid.
As of now #AWS #Lambda, #Azure #Functions and #GCP #BigQuery, #App-Engine, #Cloud-Functions are good examples of serverless services available on public clouds.
Simple Deployments/Infrastructure cost reduction – Without the infrastructure coming into picture, you pay for what you actually use. The cost of serverless is computed to nearest sub-seconds. So if your task took 17.5 seconds to complete on serverless infrastructure, you only pay for 17.5 seconds. Compare this with a VM costing where you are charged for uptime of VM irrespective of it is used or not.
Automatic Scaling and Fault tolerance – Services like AWS Lambda, Azure Functions or GCP Cloud Functions are always available and maintain their compute capacity across availability zones to provide a robust infrastructure. These services can create multiple instances of execution VMs as required to serve the incoming requests in parallel.
Operations cost reduction – By automating the repetitive tasks on serverless services, you save on operations costs and time.
Repeatable results – Since the serverless functions can execute on any of the pool machines without the user knowing the execution VM. The developer are forced to create self-contained functions. This leads to better repeatable results.
Extremely cheap – On AWS, the Lambda free tier includes 1M free requests per month and 400,000 GB-seconds of compute time per month. No other compute service is cheaper than this. Similar pricing plans exists for Azure Functions and GCP Cloud Functions.
At first glance the Serverless architecture seems to be the silver bullet for all the problems. But it has certain restrictions too:
The VM capacity for functions is limited by limits set by the cloud providers. One of the main limits is the execution time of the functions itself, for both AWS lambda and Azure Functions the default limit is set to 5 mins. Similarly, the disk capacity and memory are limited too. You can refer to following links to understand the limitations
o AWS Lmbda - https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list
o Azure Functions - https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale
The languages available to write serverless Functions is limited to few languages currently. For example python, powershell etc still experimental in Azure Functions. Similarly AWS lambda only supports few javascript like languages (node.js etc) , python, java and C#. They also put restriction on the version of the language. Besides while the VM spawned for Function execution might not have all the relevant libs required.
Since serverless functions (AWS lambda , Azure Functions , GCP Cloud Functions can be triggered by a scheduler or an event or a Web-call (via web-hooks) we can use Serverless functions to solve many use-cases. Few are listed:
To schedule background cleanup of resources – Let’s say you have some local resources on cloud that are not needed in between certain times (say 6:00 PM - 8:00 AM). You can write a serverless function that deletes the resource after a specific period and then recreates it half an hour before the usage period. Don’t forgot to use functions to backup the data too.
Replacing existing batch jobs with functions - Your existing batch jobs can be replaced with serverless functions on cloud to achieve similar functionality without maintaining any additional infrastructure.
Create notification system – The serverless functions can be triggered periodically to send out custom alerts.
Time ranged clusters – We recently built a sophisticated system for a client to build a time ranged clusters mechanism, where clusters were created for a time duration and destroyed after a period of time with mechanisms for notification and time extension. This helped client to save at least 40% on expensive Bigdata clusters cost (based on month-on-month billing).
More use-cases can also be found at cloud providers's web-site.
Hope this gives you sufficient information to start with serverless functions available in public cloud. Do leave a comment if you want to know more or have any questions.
About me: I am an IT professional with 15+ years of experience. Currently working as cloud architect. Also investing my time on BigData and blockchain technologies. Tech learners is my attempt to introduce the technology in simple terms.