Before we understand serverless architecture and implementation, it is important to understand its history and how it has evolved. In the beginning, there were physical servers. Although users had complete control over physical servers, there were a lot of disadvantages, as follows:
- Long gestation periods between the ordering and the actual deployment of the server
- Capital-intensive in nature
- Waste of resources
- Lower return on investment
- Difficult to scale out and up
A natural evolution from physical servers was virtualization. Virtualization refers to the creation of virtual machines on top of physical servers and deploying applications within them. Virtual machines provide several advantages:
- No need to procure physical hardware
- Comparatively easier to create newer virtual machines
- Complete isolation of environments
- Lower costs compared to physical servers
However, virtualization had its own set of disadvantages:
- Still dependent on the physical procurement of a server for scaling out after a number of virtual machine instances
- Still costly because of human and hardware dependence
- Wastage of compute resources—each virtual machine runs a complete operating system within it
- High maintenance costs
The next evolution was IaaS from cloud providers. Instead of procuring and managing data centers and infrastructures, the strategy was to create virtual machines, storage, and networks in the cloud. The cloud provides software-defined infrastructure services and hides all the details related to physical servers, networks, and storage. This had some advantages:
- No capital expenditure, only operational expenses. Functions are charged based on consumption model instead of fixed cost (although there is an App Service model based on fixed cost).
- No gestation time to create new virtual machines—new virtual machines can be provisioned within minutes rather than hours.
- Flexible size of virtual machines.
- Easier scaling up and out of virtual machines.
- Completely secure.
Virtual machines in the cloud do have some disadvantages:
- Requires active monitoring and auditing
- Requires active maintenance of virtual machines
- Scalability, high-availability, and performance of virtual machines should be managed by users – any degradation and subsequent improvement is the user's responsibility
- A costly option because users pay for the entire machine whether it is used or not
The cloud also provides another pattern for deploying applications, popularly known as PaaS. PaaS provides abstraction from the underlying infrastructure in terms of virtual machines, virtual networks, and storage on the cloud. It provides a platform and an ecosystem where users do not need to know a thing about the infrastructure at all; they can simply their application on these platforms. There are definite advantages using PaaS compared to IaaS, but there are still better options. The main disadvantages of PaaS are the following:
- PaaS applications are deployed on virtual machines behind the scenes and the payment model is not granular; it is still at the deployment level.
- PaaS still demands monitoring for scaling out and in.
- Users still need to identify the requirements for their platform. There are limited options available for different types of platform. Azure exclusively provided a Windows-based environment until recently when it began to offer Linux as well. Moreover, the installation of packages, utilities, and software is the responsibility of its users.
Further, a new paradigm emerged known as containers, which is primarily made popular by Docker. Containers provide a lightweight, isolated, and secure environment that has all the benefits of virtual machines, minus their disadvantages. They do not have a dedicated operating system and instead rely on a base server operating system. Containers come in both IaaS and PaaS patterns. Containers provide many advantages:
- Faster provisioning of environments
- Consistent and predictable creation of environments
- Eases the creation of microservices architectures
- A rich ecosystem with advanced services from Kubernetes, Swarm, and DC/OS
Containers do have a few disadvantages, they are as follows:
- They require active monitoring and auditing.
- They require active maintenance.
- The scalability, high-availability, and performance of containers should be managed by orchestration tools like Kubernetes. These orchestration tools need extension deployments and skills to manage.
Serverless by definition is a deployment paradigm. It can be deployed on virtual machines as well as on containers. To get the best out of serverless, they should be deployed on to containers to take advantage of their faster creation and tear-down features. This will have a direct impact on scalability and high availability of serverless platform and also will be much faster, quicker compared to a virtual machine.