You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
The Cost Optimisation pillar of the GCP Architecture Framework focuses on maximising the value you get from every pound or dollar spent on Google Cloud. Cost optimisation is not about spending less — it is about spending wisely. The goal is to deliver the same (or better) outcomes at the lowest possible cost, without sacrificing reliability, security, or performance.
| Principle | Description |
|---|---|
| Measure and attribute costs | You cannot optimise what you do not measure — implement cost visibility first |
| Right-size resources | Match resource allocation to actual workload requirements |
| Use committed discounts | Lock in savings for predictable workloads with committed use discounts |
| Leverage serverless | Pay only for what you use with services like Cloud Run and Cloud Functions |
| Eliminate waste | Identify and remove idle, orphaned, and over-provisioned resources |
| Architect for cost | Consider cost implications in architectural decisions from the start |
| Feature | Description |
|---|---|
| Billing accounts | Link projects to billing accounts for consolidated invoicing |
| Billing export to BigQuery | Export detailed billing data for custom analysis and dashboards |
| Budget alerts | Set spending thresholds with notifications at configurable percentages |
| Cost breakdown | View costs by project, service, SKU, and label |
# Enable billing export to BigQuery (configured in Console)
# Then query your costs:
SELECT
project.name AS project,
service.description AS service,
SUM(cost) AS total_cost,
SUM(usage.amount) AS total_usage
FROM `my-billing-project.billing_export.gcp_billing_export_v1_XXXXXX`
WHERE DATE(usage_start_time) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
GROUP BY project, service
ORDER BY total_cost DESC
LIMIT 20
# Apply labels to resources for cost tracking
gcloud compute instances update my-vm \
--update-labels=team=platform,environment=production,cost-centre=engineering
# Label a GKE cluster
gcloud container clusters update production-cluster \
--region=europe-west2 \
--update-labels=team=backend,product=orders
# Create a budget with alert thresholds
gcloud billing budgets create \
--billing-account=0X0X0X-0X0X0X-0X0X0X \
--display-name="Production Budget" \
--budget-amount=5000 \
--threshold-rule=percent=0.5 \
--threshold-rule=percent=0.8 \
--threshold-rule=percent=1.0
Right-sizing means matching your resource allocation to actual workload requirements — neither over-provisioned (wasting money) nor under-provisioned (degrading performance).
# View VM right-sizing recommendations
gcloud recommender recommendations list \
--project=my-project \
--location=europe-west2-a \
--recommender=google.compute.instance.MachineTypeRecommender
# View idle VM recommendations
gcloud recommender recommendations list \
--project=my-project \
--location=europe-west2-a \
--recommender=google.compute.instance.IdleResourceRecommender
GCP allows you to create VMs with custom vCPU and memory configurations, avoiding the waste of standard machine types:
# Create a VM with exactly the resources you need
gcloud compute instances create custom-vm \
--custom-cpu=6 \
--custom-memory=20GB \
--zone=europe-west2-a
CUDs provide significant savings for predictable workloads in exchange for a 1-year or 3-year commitment:
| Commitment | 1-Year Discount | 3-Year Discount |
|---|---|---|
| Compute | Up to 37% | Up to 55% |
| Memory-optimised | Up to 37% | Up to 55% |
| Cloud SQL | Up to 25% | Up to 52% |
# Purchase a committed use discount
gcloud compute commitments create my-commitment \
--region=europe-west2 \
--plan=36-month \
--resources=vcpu=100,memory=400GB
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.