GCP — small things — big savings

Cost saving is a constant goal for any organization. While things are less panicking when setup is small but gradually as the setup grows, it becomes a real challege to control cost. There are few small things we could do to save cost while working with GCP.

Your saving is your earning

Your saving is your earning.

Delete Unused Reserved external IP addresses

$7.30 per month is charged by google for unused external reserved IP address.

So how to find unused IP addresses and delete them?

  • You can go to IP address view in GCP.
  • The table has a column called “In use by”. If the value in this column is “None”, then this IP address is not used and can be deleted.
  • Please make sure that none of your external IP addresses are left unused.

Don’t reserve minimum no of instances when using cloud run if not needed

  • Cloud run supports the setup of minimum no of instance that will be running all the times. This is a feature to reduce the cold start.
  • While this is good features to avoid latency during initial calls, this could result in a lot of extra cost.
  • If your application is not a critical client facing application or if cold start of a few seconds is not a problem for you, then set minimum no of running instances to 0. This will save cost.

Use 2nd generation cloud functions

  • 2nd generation cloud function uses cloud run under the hood.
  • It supports concurrency which means that 1 instance can handle multiple requests.
  • With concurrency enabled, we can reduce the min instances (instances always running to avoid latency).
  • This will reduce cost.
  • Here we can read about features of 2nd generation cloud functions.

If using Bigquery — Try Bigquery commitments

Avoid assigning external IP address to VM instances rather use load balancer to expose traffic outside of VPC

Use Cloud Storage with GCSFUSE for small shared filesystem storage requirements instead of Filestore

  • If there is a need to have a filesystem storage attached on multiple instances, a cost effective alternative is to use cloud storage and mount is using GCSFUSE to the VMs.
  • There is a performance trade-off with this approach.
  • Ideally filestore is meant for this purpose but even a minimal filestore configuration will cost around 250 euros/month.
  • Using cloud storage with GCSFUSE, the cost is negligible.

Network Cost due to egress traffic

  • Networks that use internal IPs in same zone to communicate can save google cloud egress bandwidth costs.
  • Check below table for more details.

Logs Storage cost

  • The first 50 GB / month is free in cloud logging.
  • Effective April 1, 2023, storage costs apply to logs data retained longer than 30 days. For pricing details, see Cloud Logging pricing summary. To review the billable storage for your log buckets, go to the Logs Storage page of the Google Cloud console.
  • Be wise about what to log. It’s not free.

Network flow logs and firewall logs

  • Enabling firewall logging can generate a lot of logs. Please be wise while enabling them.
  • VPC flow logs keeps track of src_ip, src_port, dest_ip, dest_port and protocol. Enabling VPC flow logs can generate a lot of logs.
  • This will take your quota of free cloud logging storage and result in cost for storage beyond 50 GB/ month.

Audit Logs

  • Admin logs — enabled. 400 days. No charge.
  • Data Access logs — should be enabled except for big query. 30 days default. Costs .50$ per GB data ingestion.
  • System Events — enabled. 400 days. No charge.

Other

Google Recommendations to reduce resources (CPU & Memory)

  • Google provides recommendations for under utilised resources.
  • Go to cloud overview -> Recommendations.
  • There are recommendations about the unused resources and how much we can save if they are deleted.
  • There are recommendations about reducing image sizes and how much we can saved if machines are resized.
  • Please make a habit to visit this section at least once every month and act on them if needed.
  • This will considerably save cost.

Setup Horizontal autoscaling

  • We all are always used to over provision resources to have a better customer experience.
  • With GCP there are many compute services ie: cloud run, MIG, GKE, App Engine where scaling is done automatically for us without paying more and compromising one application performance.
  • Use horizontal autoscaling where possible to get the best of both worlds.

Setup alerting and monitoring for underutilisation threshold if autoscaling is not setup

  • We all are always worried of setting threshold to CPU and memory usage of around 70–80 so that we are notified on time in order to scale things up.
  • However it’s not a common practice to setup threshold for underutilised resources. Like scaling down the memory and CPU when usage is below 40% for example.
  • Setting such alerts can result in less cost.

Don’t create load balancer for each service

  • Some teams try to create load balancers for each service/application to make is publicly accessible using a single static IP.
  • In GCP, we can use feature rich global http/s load balancer. They are proxy load balancers and can route traffic to different services/end points based on path rules and host rules. This can considerably save cost.
  • They Can integrate with cloud IAP to abstract application authentication and authorisation for all apps and have common method for all the applications.
  • They can integrate with cloud armor to provide edge protection and backend protection.

--

--

Amit Kumar Dube (अमित दुबे)

@AmitDubeDev | Professional GCP Architect | Terraform ACE | Lead Infra Consultant | Hindi Speaker