Serverless solution. When and why should we use them.
Serverless solutions are becoming more and more popular. They allow developers to focus on creating business logic without having to deal with infrastructure issues.
What is serverless really? Does this mean that there are no servers?
Serverless solutions do not mean that there are no servers – of course there are servers because the cloud is based on them. In this case, we simply focus on system delivery as the software supplier, and the responsibility for infrastructure management falls on Microsoft, Amazon or Google as suppliers. An additional benefit of serverless solutions is the ability to automatically scale due to the load. As a result, we are able to provide a solution that meets the high expectations associated with availability.
Is serverless the perfect solution?
In the case of this type of service provision, it should be remembered that they are billed on “pay as you go” basis, i.e. we pay for what we actually used. Therefore, if our software is hosted locally and rarely runs, we still pay for unused resources. In the case of cloud and serverless solutions, this is the moment when we can actually save money because we do not pay for the server’s idle time. The situation is different when our software generates a lot of traffic. At this point, the cloud solution can be much more expensive than ordinary hosting? Example? Here you are:
As you can see there can be a big difference between cloud and standard hosting.
When should you use serverless solutions then?
If the example above scared you then calm down. There are several scenarios when it’s actually worth considering cloud. Below is a short list of question and if you answer to most of them “yes”, then serverless might be for you:
- Is your application small and divided into modules?
- Do individual modules have well-defined inputs and outputs?
- The application does not generate a lot of traffic (peaks).
- Do you need a solution that scales very quickly?
- Part of the application logic is done on your server side anyway?
- Most application logic is done on the client side?
Also serverless will also work great when building Proof of Concept where we are sure that the generated traffic will not cause a significant increase in costs but thanks to focusing only on the application we will be able to provide such a solution quickly.
What options do we have when it comes to serverless solutions?
There are many serverless solutions available on the market, but of course the most popular come from 3 major cloud providers:
- Microsoft Azure Functions
- AWS Lambda
- Google Cloud Functions
All of them are similar and allow you to make a quick deploy of source code using many languages and run your application.
How might the sample serverless architecture look like?
Below you can find simple serverless architecture example. As you can see there are no Virtual Machines or external servers. Whole application is hosted inside Azure Functions using API Management, Azure Functions, Azure SQL Server, Blob Storage and Table Storage. Every microservice hosted inside Azure Functions can be written in different language (C#, Java, NodeJS etc.).
Summary
Serverless solutions have many benefits, but before you decide to go for them, you should carefully analyze your system and the conditions in which it will work. If the priority for you is scalability, time to market and finally application is built in the right way, then serverless is an ideal solution.