Cost optimization with GCP
It’s all money!
For a personal project, I use Google Cloud Platform to run a small cloud application.
- About 100$ CAD/month of Cloud costs.
- I was previously using GCP provided credits, which meant actually zero cost to my own budget.
- The credits have now ran out and I now have a good motivator to optimize the workload!
How to start optimizing a cloud workload
There are a couple of different ways to start this, but you want to start with understanding the application and the cloud services in use.
A typical optimization flow looks like the following
Audit --> Optimize --> Validate --> Continuous Optimization
This is usually covered by a FinOps team attached to a Cloud Center of Excellence (CCOE). The FinOps practice is aligned to the concept of DevOps, where the responsibility/accountability is shared/owned by squads working in tandem.
After a bit of thinking, I aligned towards these 4 corrective actions.
Change the Compute Engine machine type + lower specs
- From the current usage, I judge that lowering the specs + machine type can drive savings
Change the disk type
- From the current usage, I judge that lowering the disk type can drive savings
Remove the load balancer and switch to a GCP GCE External IP
- We can remove the dependency on a load balancer by using a Public IP attached directly to the VM
- This is very application specific as it removes a lot of the flexibility/scalability of a cloud native solution. In this case, it’s an acceptable tradeoff to further reduce costs.
Remove the NAT Gateway
- As we are removing the Load Balancer and adding an External IP, we can also remove the NAT Gateway and further reduce costs
Overall, this should drive a 70-75% cost reduction. While we lose a lot of the “value” of cloud infrastructure, this is a small project that does not benefit too much from these advantages.
How I got there
We can start with the GCP console Billing hub to get a good understanding of our cost breakdown –> https://console.cloud.google.com/billing
Using the web interface, we can export the list to CSV for easier manipulation. We can go item by item and understand the optimization options.
|Regional External Application Load Balancer Forwarding Rule Minimum for Montréal (northamerica-northeast1)
|GCP load balancer do not offer a lot of flexibility for optimization. You will pay for the number of LB rules for URL forwarding per hour, bandwidth GB IN + OUT
|E2 Instance Core running in Montreal
|Compute Engine offers discounts with Committed Use Discounts (CUDs) to commit to a level of consumption for 1-3 years. You are then charged per month for a fixed amount no matter the actual consumption. A second option would be to rightsize the instance to a lower hardware spec. A third option is to pick a different instance hardware class with lower $/hour cost.
|E2 Instance Ram running in Montreal
|Same as the above
|Micro Instance with burstable CPU running in Montreal
|This is the VPC connector. It allows a GCP Serverless Cloud Function to interact with a resource inside a VPC. This is a design choice, but you can influence the cost by indicating a smaller machine type for the VPC connector and set lower maximum limits as this machine scales based on usage.
|Balanced PD Capacity in Montreal
|This is used by the virtual machine disk. You can influence pricing by selecting a lower disk tier or reducing the size of the disk.
|Networking Cloud Nat Gateway Uptime
|This is the managed NAT service provided by GCP. There is an hourly uptime cost as well as a data processing cost.
|Storage PD Capacity in Montreal
|This is from the Cloud Function VPC connector. Behind the scenes, it uses Compute Engine which leverages a disk. You are charged for that cost
|Artifact Registry Storage
|You can lower the amount of Artifact stored to reduce the overall cost.
|Those are the Cloud Scheduler jobs. The more jobs are scheduled, the more $/month
|Network Internet Standard Tier Egress from
|Egress from the Load Balancer . Lower usage would mean lower cost/month
|Networking Cloud Nat Data Processing
|Charge from the NAT gateway egress/ingress
|Regional External Application Load Balancer Outbound Data Processing for Montréal (northamerica-northeast1)
|Charge from the GCP Load Balancer processing data