Cloud computing is by itself a revolution in the IT industry. With its compelling advantages (extreme flexibility, user-friendliness, etc…), it became a common choice for many companies that would like to escape the pain and hassle of managing their own hardware and infrastructure.
However, having everything from using an IP to deploying a scalable server and databases with a click of a button is not always a good thing. with this ease, users can quickly lose control of increased and unnecessary costs.
~ Approx, about a year and a half ago, I was hired as a “DevOps Engineer” for a company that runs a TV show. it was a 4 months project.
Studying their infrastructure, we’ve set a goal to minimize the cost without affecting their availability. The reason I’m writing about this is to have some generic steps to take whenever anyone would like to try and optimize their cost. And here’s how it was achieved:
1- Scan for unneeded resources
You or other infrastructure managers create resources for some tasks, and with business changes and moving forward, sometimes we tend to forget about them. In my case, a dedicated server for real-time “comments” was up and running while management have earlier decided to disable commenting on their website and the comments section was removed. but the instance was still up!
A good approach is to create an inventory checklist (needed load balancers, databases, servers, etc) and keep this list up to date with your business requirements.
2- Your hardware location matters!
Amazon web services, like many other cloud computing companies, offer resources in different datacenters, in different regions… However, what you might or might not know is that different regions have different pricing. For example, a t2.medium instance costs 0.029 USD per hour in Ohio, while the same t2.medium instance costs 0.039 USD per hour in Sydney. Depending on your application, it is typically better if you choose resources closest to your customers/services visitors in order to minimize your delay. But you might be able to find a middle ground balancing both the cost and the distance. So a good strategy is to find the closest region to your customers with the best possible pricing.
3- Are you really using your reserved computing power?
Monitor monitor monitor!
In order to avoid headaches, we tend to reserve instances bigger than our needs… “for future scalability”. This is not budget friendly. Always monitor the status and percentage usage of your instances (CPU / RAM / DISK) and reserve your instances accordingly. If you don’t need the power, don’t pay for it. On the other hand, if you notice some abnormal resources usage, do collaborate with the development team. software optimization could save you a fortune.
4- Benefit from contracts
If you are sure if your company’s short-term future, go ahead and pre-pay if possible. For example, an m5.4xlarge instance costs 0.665 USD / hour. If you pay a year upfront, its cost would change to 0.621 USD / hour. And don’t forget, If you’re willing to keep those servers on 24/7, use reserved instances instead of on-demand instances. And whenever you can, use spot instances instead of on-demand if you don’t mind the interruptions. If you don’t know what’s that, read more about spot instances here.
5- Do NOT be afraid of scaling
After monitoring your application resource usage, you probably know its peak time, when you need to serve more and when to serve less. Take advantage of AWS’s autoscaling and set your resource utilization rules. for example, if the CPU runs at 70% ~ 80 % for more than 4 – 6 minutes, scale up to keep your performance steady. Otherwise, scale down to lower your bill.
6- Seriously, turn things off
Testing servers, staging and UAT environments do not need to be online at all time. check your team’s behavior and usage of these and similar resources and act accordingly. For example, you might turn them off on weekends and after working hours.
7- Do check and compare bills
Do not just pay and forget! comparing bills from month to month is important. If a bill goes way higher, check what changed and try to keep track of everything.
8- Finally, do benefit from Amazon
From my experience, Amazon tries to help its users as much as possible. they have pretty much writings for everything, Including this exact cost optimizing topic! So for more about this, go ahead and check their tutorials here.
And as always, feel free to send a message if you had any thoughts or questions regarding this topic, or just leave a comment below.