RomanMarch 13, 2021
The term serverless describes the possibility for developers to run their code without maintaining servers themselves. Developers can focus completely on solving business problems with code and leave technical problems such as server maintenance and scaling to the cloud providers.
Types of Serverless
There are different types of serverless products. First there are cloud functions. AWS, Azure and Google Cloud Platform offer their variations of a cloud function implementation, but the principles are always the same:
- 1. Chose your stack: python, node, java, c#...
- 2. Deploy your code
- 3. You are done!
Then there are cloud container instances. Those are basically docker containers that run on a serverless infrastructure in the cloud. Here is where cloud providers differ significantly.
Azure Container Instances and AWS Fargate are suitable for background tasks, but it can get expensive, if you forget to shut down those instances at the end of a task. The high costs render those solutions useless for long running tasks like for example a web API service that waits for user requests.
The Cloud Run feature of GCP on the other hand is cost-effective solution if you need a serverless web API. They really charge you for the duration of each http request and not for the lifetime of the container instance. The downside is that you will run into short cold start delays after the container instance gets shut down. The shutdown happens automatically after some idle time. Also, there is no way to run a background task which would be of course a major exploit.
Costs of Serverless
When is a serverless solution cheaper than a solution hosted on always-on servers? To answer this question, you need to analyze your infrastructure and find computational resources that are wasting money. For example: expensive boxes that idle at least in 30% of the time. From my GCP bills I was able to extrapolate that an Azure VM would have cost me as much as my Cloud Run Instance operating 24/7 (both with comparable computing power). If you do not have 24/7 traffic and can live with a short delay during a cold startup then Cloud Run might be a cost saver for your web APIs. Considering the costs to run and maintain your own servers the overall infrastructure costs might be reduced significantly.
Serverless products offer a very friendly environment for software developers enabling them to concentrate more on the business instead of spending their time with technical issues such as server performance and scaling. Costs can be a driving factor when there is potential to reduce unused and cost intensive computing power.