Software developers are familiar with removing bottlenecks by optimizing their code, be it CPU, disk, memory or network bottlenecks. With the move to public clouds like AWS, a developer or architect needs to work on optimizing run costs. AWS and other public clouds charge by usage, so if you consume a resource or a service, you are paying. This is unlike systems of old.
Prior to the cloud, developers had to build software to the target system, which was typically purchased upfront. Therefore, the cost was calculated over the lifetime of the system. No need to worry about run costs. However, moving to a public cloud requires a rethink.
Cloud Costs
You pay for everything you use in a public cloud. Here is a list of items you can pay for in the public cloud, it is not a complete list:
- Network traffic
- Number of vCPU, vRAM and Disk
- Message size
- Monitoring and frequency of monitoring
As this is not a complete list, please investigate your own cloud for specific costs. Once you know the costs involved you calculate the costs across your application. Then see where you can save the most money.
Optimizing Run Costs
If you have your own servers in the cloud, beyond production, then look at bring them down when they are not needed. If your team works 9-5, then why have systems running and costing you money? Use infrastructure as code tools and techniques to rid yourself of unneeded costs. In the cloud, it is highly recommended to use infrastructure as code. With control over down time, now it is time to look at server instance sizing.
You picked the smallest instance your code would run on, so you code save money, right? Well, this is not always the best move. It has been proven on AWS, moving a workload to a large system may result in faster runs, which is great for batch processing. So, test your server instance size to help with costs. Beyond server instance sizing, you have a few more options for your servers.
AWS costs can differ from region-to-region along with instances categories. If you have a large job to run, you may be able to run it in region you normally do not use. If your timing is right, costs for spot and on-demand instances could be much lower. Beyond on-demand instances, the default instance type in AWS, are reserved and spot instances. These instance types can further reduce your costs, so consider them when doing your cost optimization. Now with the low hanging fruit, it is time to look at code.
Optimizing Services
With AWS options available, one needs to see if it is better to run their own servers or to use AWS Lambda. If you are using your own server, then code changes may not have a large impact, while code changes to code in AWS Lambda will. AWS Lambda charges for execution time, while server instances are charged for the life of the server. So, if your server is not executing code, you are still paying for it.
Optimizing run costs in the cloud is not hard, focus on low hanging fruit and the most bang for your buck. Then, try the options available to you in your cloud provider and see which is the better option for you.
Click here to learn more about AWS cost optimization.