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.

Optimization options

Change the Compute Engine machine type + lower specs
  1. From the current usage, I judge that lowering the specs + machine type can drive savings
Change the disk type
  1. 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
  1. We can remove the dependency on a load balancer by using a Public IP attached directly to the VM
  2. 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
  1. 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 –>

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.

Service description Service ID Optimization option Optimization option
Networking E505-1604-58F8 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
Compute Engine 6F81-5844-456A 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.
Compute Engine 6F81-5844-456A E2 Instance Ram running in Montreal Same as the above
Compute Engine 6F81-5844-456A 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.
Compute Engine 6F81-5844-456A 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 E505-1604-58F8 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.
Compute Engine 6F81-5844-456A 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 149C-F9EC-3994 Artifact Registry Storage You can lower the amount of Artifact stored to reduce the overall cost.
Cloud Scheduler 1F14-4801-0E16 Jobs Those are the Cloud Scheduler jobs. The more jobs are scheduled, the more $/month
Compute Engine 6F81-5844-456A Network Internet Standard Tier Egress from Egress from the Load Balancer . Lower usage would mean lower cost/month
Networking E505-1604-58F8 Networking Cloud Nat Data Processing Charge from the NAT gateway egress/ingress
Networking E505-1604-58F8 Regional External Application Load Balancer Outbound Data Processing for Montréal (northamerica-northeast1) Charge from the GCP Load Balancer processing data
Laurent Dumont
I route packets and juggle bytes