Optimize hosting cost with serverless computing

Enterprise transformation is a continuous process, it is vital to address business imperatives. Typical business imperatives involve performance excellence, cost excellence and operational excellence – digital initiatives continue to play important role in most of these transformations. Such organization needs can be addressed by the five pillars of well-architected framework. All cloud leaders unanimously agree on these five pillars, they can be described as below:

  1. Cost Optimization – maximizing value of deliverable
  2. Performance Efficiency – being able to step up to customer needs
  3. Operational Excellence – ensure lights are always on
  4. Reliability – being able to recover from failures and continue to function
  5. Security – protecting information system from threats

While all the pillars are important, this write-up is specifically focused on cost optimization. For our discussion, consider deployment of a typical two-tiered web application, it requires at least a web server and database server. For simplicity, container based deployment is not considered though it’s a good candidate for cost reduction.

Let us consider an application with 1 million hits per month, 99.95% availability requirement and steady traffic. Such an application would require two web servers behind load balancer and an active-passive database deployment at minimum. For simplicity let us presume all the costs for other components remain same throughout. The tired redundant web/database deployment approach such as this one using general purpose compute options to support moderate traffic would cost approximately $500 to $600 per month. This is considering a 2 vCPU and 8 GB RAM instance which approximately costs $150 per instance (rounded to closest number for reader convenience).

When it comes to cost optimization, a common practice is to use auto-scale configurations, such an approach would reduce number of minimum web servers to 1. Auto-scale configuration would ensure the solution is scaled-out appropriately when load increases, ensuring both availability and scalability. Revised approach reduces cost by 25-30%, to about $450 per month. This cost can further be optimized by considering spot instances, in our case we will stick to on-demand instances. Additional compute, if provisioned would result in additional cost, same can be controlled with scale-in configuration which would reduce instance based on utilization.

Further cost optimization can be observed through use of reserved instances. The reserved instances require long term commitment, savings may range from 40% to 60%. While there is cost advantage, this approach may require upfront payment resulting in capex kind of model. Considering 40% savings, the monthly deployment of $450 would reduce to $270.

What would have cost $600 in traditional deployment approach can be reduced to $270, it is less by 55%. The biggest advantage so far is that there is no change to underlying application architecture. Majority of the applications in your organization can benefit from such cost optimization. Annually this kind of deployment can save approximately $3,500 to $4,000 per application.

While I have done such optimizations in the past, the serverless computing approach can produce extraordinary savings. The approach, however, requires either great deal of refactoring or re-engineering. A simplistic approach in serverless computing world would include – object storages (Amazon S3 or Azure Blobs) for hosting static websites, API Gateway for publishing APIs and serverless computing (AWS Lambda or Azure Function). Add additional components such as Queue for optimizing solution may be required, for now we will keep the concept simple.

Both on Azure and AWS the API gateway and serverless compute options are available either in the form of pay-per-use or through reservations. Reserving services provide better performance SLAs, but cost wise it may impact adversely. On the other hand, consumption based approach optimizes TCO significantly, requiring suitable architectural considerations to mitigate SLA shortfalls.

In this serverless approach, user interface would be hosted on object storage, this takes away the need for web servers entirely. API gateway and serverless computing can take care of server-side interfacing & computing needs. AJAX can be leveraged for APIs calls to persist data. This approach can result in significant savings. Both AWS and Azure provide 1 million free API calls, similar free offering is also available for serverless computing (AWS Lambda or Azure Function). Essentially for our example there is no compute cost, it’s all free! Static website hosting costs less than $10 per month. With this approach the total web application hosting cost gets reduced to $190. The static web hosting would cost $10 and database $180.

Let us presume the application is simple, there is hardly any need for maintaining relational database and it can be replaced with NoSql. Both AWS and Azure provide NoSql options. If the application persistence requirements are very simple, the object storage itself can be leveraged for data persistence. Saving, updating or replacing 1 million objects in S3 or Azure Blob on monthly basis would cost less than $10 per month. With this architecture revised total application hosting cost would be lower than $60 per month. Biggest trade-off with this approach is the need for re-engineering. One must consider this approach with thorough cost-benefit analysis.

Following is the cost optimization summary table:

#ApproachWeb Server CostDatabase CostMonthly TotalYearly Total
1Traditional Hosting – 2 web servers, 2 database servers$300$300$600$7,200
2Improved auto-scale configuration – 1 web servers, 2 database servers$150$300$450$5,400
3Reserved instances – 1 web server, 2 database servers$90$180$270$3,240
4Static website with API, serverless computing and RBMS$10$180$190$2,280
5Static website with API, serverless computing and NoSql/Object storage$10$50$60$720

The cost benefits outlined are for a single application, a midsize company with 20 such applications can save approximately $100,000+ every year. It is very important to note that real-world scenario may have additional technology components such as queues, workflow, reporting, notifications, alerts, etc. They may also have needs for managing and maintaining relational databases. My suggestion would be to look at optimization objectively and pragmatically evaluate serverless computing as an alternate way of doing things, you may be able to unravel other benefits.

As a final note all the cloud leaders have published well architected framework, you can read more about them and five pillars at following links:

Leave a comment