Why & When to Go Serverless
Serverless Applications and Serverless Computing are some of the terms that you will come across frequently when trying to choose from various options being offered by cloud service providers like Amazon Web Services (AWS) and Microsoft Azure (Azure). The term serverless accompanied with the word application could be confusing, as it is contradictory to the conventional methods of developing and deploying applications. In this blogpost, we will attempt to explain what serverless applications are and what exciting benefits they bring to the world of cloud technologies.
Serverless applications are built using the services provided by cloud service providers like AWS or Azure, without having the developer to worry about the underlying infrastructure. The core of serverless applications is made from cloud-native services such as AWS Lambda or Azure Functions, which offer Functions as a Service (FaaS). These services provide the ability to write event driven code functions in any of the supported languages. The functions are executed automatically when the associated events are triggered, creating an automated chain of events which can range from an API being called, uploading a file to the cloud or even invoking other serverless functions.
Serverless is the fastest-growing cloud service model right now, with an annual growth rate of 75%.
Source: RightScale’s 2018 State of the Cloud report.
One might wonder what benefits serverless applications provide or why are they getting so much traction these days. The answer to that question is in the pricing model of all of these services which is based on the philosophy that you only have to pay for what you use. Let’s consider Lambda as an example, the price of using Lambda is primarily based on how many times a function is triggered along with some other factors like the function execution time and the resources it utilizes. In contrast to non serverless services that are charged by the number of hours the service was up for.
If a business or developer runs an application on an instance or virtual machine hosted by a service that charges by the hour, they would essentially get charged for the total uptime of the instance, irrespective of whether there are any users using the application or not. If the same application is deployed using serverless services, it will be available all the time, but the account will only be charged whenever an end-user makes a request or uses the application.
Serverless architectures can be very effective for use cases where you want an application that is always up and available, but does not have continuous and constant incoming requests. The application can have a large number of incoming requests at certain times and then have large periods of stagnation with little activity. Other than that, asynchronous or event based tasks like CI/CD pipelines, multimedia processing, and scheduled batch jobs are well suited for serverless model. A couple of other benefits tied to adopting the serverless computing approach are mentioned in the figure below:
While serverless applications are bundled with various benefits, it is important to understand their core limitations that are often tied to the type use-cases and application models. From the pricing model of serverless services, it is pretty obvious that if the incoming events are large in number you would get charged more based on every input trigger. Services like Lambda or FaaS have limitations such as the amount of available RAM and accessible disk space being fixed for a Lambda function. Hosted functions also suffer from an issue known as Cold Starts, which means that every time a function has been dormant for a while it will take more time to spin up on the next request and thus cause a slight performance penalty. This issue can be minimized by using a runtime which suffers less from the cold-start penalty like Python or Node.js. It can also be minimized by reducing the overall function size.
Cloud computing also brings some limitations for serverless applications like vendor lock-in, where the switching cost to a different vendor is pretty high. If you are building a serverless application, you are committing to a specific cloud service provider and building your application around their infrastructure making switching across-platforms very difficult.
With all things considered, serverless is an interesting and in many cases a beneficial approach to building applications on the cloud efficiently in an agile manner, without worrying about managing the underlying infrastructure. It provides additional choices to solution architects while designing application architectures with minimal cost implications for their organizations.