In this article, I am going to introduce you to Serverless technology in various flavors along with a usecase and its benefits.
What is Serverless?
First of all, Serverless does not mean 'No Servers!!' (It is a misnomer). There are various definitions for Serverless, we will try to look at what Serverless means in various contexts.
Let me illustrate through an analogy.
Let us consider a scenario where, there are a number of doctors (dentists, chiropractors etc) who want to serve their patient, but they do not want to invest in real estate for the clinics, equipment and also do not want the burden of managing/repairing their equipment.
To cater to their needs, an investor comes forward and builds a huge building and also procures all the necessary tools and instruments needed by various doctors. When a patient arrives, the doctor will be provided any vacant room and the room will be quickly setup with all the instruments. Once the consultation completes, the room is available for other doctors. The doctors only pay for the hourly consumption of the room and the instruments.
This is the Serverless model, except that, rooms and instruments could be related to servers and the infrastructure required, whereas the incoming patients could be related to the incoming service requests. Application developers can just focus on writing application logic and the code will be run on servers provisioned on the fly by the cloud provider.
How does Serverless work?
Serverless has its roots in 'Function As a Service' paradigm. When we write a function which adheres to a particular definition, the function is deployed and served by the underlying platform when a request arrives.
Serverless Technology works in a similar way, wherein, we have to implement a function which provides a particular behavior and define trigger points which could invoke the function. The trigger point could be a HTTP invocation, or any other event, like a message in a queue.
When the function gets the first request, an infrastructure (which could be a server/container depending on provider), is provisioned and the function is deployed, so that it can serve the request. This period is known as the ‘Cold Start’. After a certain period of time, if there are no more requests for the function, the infrastructure is tore down, thus saving money.
Thus if we have a service which would be serving requests for lets say 5 hours in a day, then we are only paying for 5 hours!. The service would be running roughly for 5 to 6 hours (some cloud providers keep the function warm for a little longer after the requests are served). This provides huge cost benefits.
Business Use case:
A logistics company which provides courier services for businesses in a particular geography, wants to build a service which provides status of a particular shipment. Since it’s end users are business clients, this service would usually be invoked only during business hours (say 8 AM to 5 PM). If this company does not use Serverless technology, then they would have to pay for the service infrastructure for all 24 hours a day. However, if they use Serverless, then they would just have to pay per use and since the service is not likely to be invoked after business hours, their cost benefits would be proportional to 62%. And in case, if the service gets invoked after business hours (just in case, some client who stays up late and uses the service), it still works!!
Since there is no need to provision infrastructure, Serverless Technology boosts developer productivity.
Serverless functions are scalable (though the definition of scalability depends on the cloud environment on which the function is hosted and might have constraints, depending on various other factors). However, in general, serverless functions offer horizontal scalability based on traffic.
Serverless Technology saves cost. In terms of cost savings, traditional architectures were on ‘Always Lights On” mode, and hence whether the application is serving requests or not, we had to pay for the infrastructure.
Serverless also removes the burden of managing infrastructure (This is true only for Public clouds, since the Serverless infrastructure is actually managed by the Cloud provider).
What are the Serverless offerings in Public Cloud landscape?
Three of the major public cloud providers shown below support Serverless.
What does Serverless mean in Private Cloud?
In public cloud, the Serverless infrastructure is managed by the cloud provider (like AWS for example) and it is much like a black box.
However, in private cloud, the serverless infrastructure has to be managed on premise and we can use various frameworks which enable Serverless technology.
On private cloud, we can provision infrastructure using products like VMWare VXRail and then deploy and use Kubernetes as a container orchestration platform.
We can then utilize some of the Serverless frameworks available on Kubernetes, which are shown above.
Similar to the Serverless model explained above, in Kubernetes, the Pods would be created on demand and the respective function/service would be deployed on the Pod.
The above diagram shows some of the prominent Serverless frameworks supported on Kubernetes and also a typical On Premise Serverless Solution.