Techletter: Serverless Architectures – a trending alternative in a fast-paced world

Raluca Fenesan at ERNI Slovakia offices.

Let us imagine a familiar scenario, where a new client starts searching for a digital solution to a business problem. ERNI takes the documentation of the potential customer, analyses the requirements and business cases, and after a few clarification rounds, proposes a solution. This solution usually consists of a chosen technology stack, rough estimations, costs and people involved in the process. Costs include not only those for people assigned in development and testing phases, but for the deployment to production and subsequent maintenance as well.

The classical approach, regardless of the size and complexity of the final product, is to use physical servers and personnel with specialised knowledge. They usually handle the production server configurations, their maintenance, OS patching, scaling in case the popularity of the application increases and so on. But if we have a small application, with low to medium complexity, the production maintenance implies more people, resources and time than expected. What seems like an easy job at first can become tedious and costly in the end.

Introducing Serverless Architectures

The term Serverless Architecture (also known as Serverless Computing or FaaS – Function as a Service) defines a new approach to running applications without the need to manage server infrastructure in a direct and physical way. Although this does not take the server out of the equation, like the name suggests, it entails that the server is abstracted to the developer and the stakeholders involved, thus enabling them to focus more on the business at hand. With this solution, there is no more hassle when it comes to configuring, scaling or managing the production servers manually or through tedious software by developers or DevOps because everything comes out-of-the-box.

Specifically, the code is uploaded on an entity called Function, on which it runs whenever it is needed. And with the pay-per-use model that this solution offers, one ends up paying only for the time the code is being executed (the function is running). This straight away reduces the costs of owning a server in the production stage as their owners usually pay monthly fees not only for hosting but for standby and downtime as well.

When it comes to Serverless, there are multiple players on the market offering a variety of packages and solutions. The following four stand out due to their popularity and wide range of services: Amazon’s AWS Lambda, Microsoft’s Azure Functions, Google Cloud Functions (GCF) and IBM Cloud Functions. As expected, these vendors offer not only the solution for deploying and maintaining code seamlessly but also their own database, security, containers, blockchain, machine learning solutions and much more.

Big industry names from various fields of business have already jumped aboard and have shifted, or are in the process of shifting their services to these platforms. Netflix, BMW, Bluedot, Skyscanner and DNB are but a few.

Even though Serverless is aimed towards reducing costs, it is not entirely free. Knowledge is key when choosing Serverless over other platforms as overspending is a risk that does exist. Nonetheless, the prices offered are low and the decision can be sustained by the help that is given by these platforms, starting with cost calculators, which enable users to granularly the activity and cost of each service in the architecture, anomaly detection tools and so on. Furthermore, design patterns and best practices have been devised from lessons learned in order to cut down on cost and complexity and are available everywhere.

Costs

The costs provided by the four big vendors do not vary by much. They each offer standard pricing or Free Tier pricing for experimental and learning purposes. For a brief overview of their standard offers, we have included the following image.

Figure 1 Standard pricing of Serverless Architecture vendors

We can take AWS Lambda as a use case to show the low cost these services offer and why it is a better choice in terms of cost than the classical approach. Prices may vary depending on the chosen regions where instances of the desired code would run.

In a Serverless environment, the cost is determined by the execution of a function, or AWS Lambda. The Lambda is a piece of code that runs in a virtual container. The execution means the time and resources taken from the moment a request hits the Lambda until the computation ends, either successfully or in error, rounded up to the nearest 100ms. A Lambda function is configured based on memory size (GB) and execution time (ms) and it can run up to a maximum of 15 minutes. The allocated memory and execution time are multiplied together to render the cost of the function, thus producing a single unit called GB-sec.

A simple example is to have a Lambda configured with the following:

Number of requests per month: 1,000,000

Duration of each request: 100ms

Amount of memory allocated (max): 512 MB

The monthly cost of this simple setup, given the standard price of 0.0000166667 USD for a setup without a Free Tier, is 1.03 USD. The following image shows the cost variance at different combinations of CPU memory of a function, given 100,000 invocations per month. As we can see, even at around 1 GB of allocated computing memory and an execution time of 2,800ms, the cost per month is under $10.

Figure 2: AWS Lambda pricing example. Source: https://www.simform.com/aws-lambda-pricing

Extending this setup for a simple web application with the following:

  • API provisioning with Amazon API Gateway
    • Enabling HTTP API requests
    • Cost per month = $1.16
  • AWS Config
    • For configuration tracking
    • Cost per month = $0.15
  • Database provisioning using Amazon RDS for Oracle (There could be a simpler option, depending on the application requirements)
    • 1 db instance = 8 GB
    • Reserved for 1 year + additional Backup Storage
    • Cost per month = $79.64

Total cost of the mentioned added resources leads us to $81.98 per month, which is better than a classical architecture design. Costs can differ based on different configurations and regions, but Amazon and the rest of the vendors offer calculators where these can be simulated and mitigated even at the analysis phase of a project to obtain a better outcome. For more information, one can check the official AWS Calculator and create their estimates at https://calculator.aws/#/estimate.

Suitable use cases

Given the fact that computation time and memory allocation have direct implications for cost, some types of applications stand out as being more suitable than others for Serverless computing. Generally, small applications are a good fit, especially when the complexity is low. Maximisation of cost derives from the short amount of time and memory needed to fulfil function invocations. Additionally, low-traffic applications are also a good fit due to their predictability. Ensuring a steady flow of users month after month will keep the costs within desired limits.

Examples of suitable applications include stateless HTTP applications, where the server performs the same task repetitively and independently; applications responsible for scheduling batch or CRON jobs; Serverless authentication; or rich-client web, mobile or IoT backends, where the server is needed just to provide data – even static – and the frontend handles the rest. However, a large application that can be broken down into smaller services that fall into the mentioned categories can also benefit from the advantages of Serverless Computing. The key to maximising the benefits of the Lambdas is in the design and taking into consideration both advantages and pitfalls.

Since computation on functions is costly, one can rule out monolith applications, as well as high-traffic or high demand ones. If there is a clear objective to avoid vendor lock-in, then AWS is not suitable either.

Conclusion

Serverless can be beneficial for clients who do not own any kind of infrastructure or personnel for their digital solutions as well as for those who already do. For the first type of customers, this approach offers a stable and reliable out-of-the-box infrastructure that requires low maintenance, and for the latter, it saves expenses and effort.

We can take advantage of Serverless solutions especially in cases of low or medium computation applications. Planning and designing the architecture is key in maximising the benefits at a small cost. Serverless vendors continue to provide features that are essential to any web application out of the box, which leads to spending less time having to design and implement them for your application from scratch. Less time spent on additional tasks means more time on what matters, the business values that one can bring to the next customer. Using this technology enables a faster time-to-market, which surely any customer wants, and can have an especially great impact for a new customer.

Finally, surveys conducted this year by Stack Overflow[1], The Software House[2] and CNCF (Cloud Native Computing Foundation)[3] suggest that Serverless is a trending technology that is becoming the tech stack option of more and more developers. AWS ranks 4th in Stack Overflow’s Loved Platforms Infographic of the Year 2020 and 3rd in Most Wanted Platforms in the same survey, suggesting that it is a technology that will continue its lifespan in the years to come. The Software House’s survey, the State of Microservices 2020, shows that there is an increasing preference towards Serverless Architectures with the top interest being AWS Lambda. Furthermore, CNCF’s survey shows that even though only a third of respondents are using Serverless in production, the percentage of respondents evaluating this option and wanting to use it in the future is also a third. This all suggests that Serverless will continue to be used in the years to come and will become the norm.

[1] https://insights.stackoverflow.com/survey/2020#technology-platforms-professional-developers5

[2] https://tsh.io/state-of-microservices/#deployment-and-serverless

[3] https://www.cncf.io/wp-content/uploads/2020/11/CNCF_Survey_Report_2020.pdf

Are you ready
for the digital tomorrow?
better ask ERNI

We empower people and businesses through innovation in software-based products and services.