GCP Cost Management and Billing

Understanding and managing cloud costs is as important as building applications on GCP. Without cost controls, a misconfigured resource or unexpected traffic spike can generate large, unexpected bills. GCP provides a comprehensive set of tools for tracking, forecasting, and optimizing cloud spend — from budget alerts to committed use discounts.

GCP Billing Fundamentals

Billing Account

A Billing Account is linked to one or more GCP projects and holds payment information (credit card or invoice). All costs from linked projects accumulate in the billing account.

Billing Account: my-company-billing
    ├── Project: production-app       (all production costs)
    ├── Project: staging-app          (staging costs)
    └── Project: data-analytics       (BigQuery, Dataflow costs)

Monthly Invoice → Billing Account → Paid by credit card or bank transfer

GCP Pricing Model

GCP charges based on actual usage — pay-as-you-go with per-second billing for most services:

ServiceBilling UnitFree Tier
Compute EnginePer second of vCPU and RAM usage1 f1-micro VM/month in us-regions
Cloud StoragePer GB stored + per operation5 GB Standard storage/month
BigQueryPer TB of data scanned1 TB queries/month + 10 GB storage
Cloud RunPer 100ms of request processing2M requests + 360K GB-seconds/month
Cloud SQLPer hour of instance uptimeNone
Network EgressPer GB of data leaving GCP1 GB/month to internet

Viewing Costs

Billing Dashboard

The Billing section in the Console shows a breakdown of costs by project, service, and time period.

  1. Go to Billing → Reports
  2. Filter by project, service, or time range
  3. View costs broken down by SKU (specific pricing units)
  4. Enable "Group by" service to see which service costs the most

Cost Breakdown Example

Monthly Cost Report: production-app project
┌───────────────────────────────────────────────┐
│  Service             │  Cost (USD)            │
├──────────────────────┼────────────────────────┤
│  Compute Engine      │  $142.50               │
│  Cloud SQL           │  $87.20                │
│  Cloud Storage       │  $12.80                │
│  Cloud Run           │  $8.40                 │
│  Network Egress      │  $22.10                │
│  BigQuery            │  $5.30                 │
├──────────────────────┼────────────────────────┤
│  TOTAL               │  $278.30               │
└───────────────────────────────────────────────┘

Budget Alerts

Budget alerts notify via email when projected or actual spending approaches a defined threshold. They do not automatically stop resources — they only notify.

Budget: production-app — $300/month
├── Alert at 50% ($150): Email to finance@company.com
├── Alert at 90% ($270): Email to finance + ops team
└── Alert at 100% ($300): Email + SMS to on-call engineer
# Create a budget via CLI
gcloud billing budgets create \
  --billing-account=ABCDEF-123456-GHIJKL \
  --display-name="production-app-budget" \
  --budget-amount=300USD \
  --threshold-rule=percent=0.5 \
  --threshold-rule=percent=0.9 \
  --threshold-rule=percent=1.0

Programmatic Budget Notifications

Budget alerts can publish to a Pub/Sub topic, allowing automated responses — like stopping non-critical resources when the budget is exceeded.

Budget exceeds 100%
        │
        ▼
Pub/Sub topic: billing-alerts
        │
        ▼
Cloud Function: stop-dev-instances
        │
        ▼
All non-production Compute Engine VMs stopped automatically

Cost Optimization Strategies

1. Committed Use Discounts (CUDs)

Committing to a specific machine type for 1 or 3 years provides up to 57% discount on Compute Engine and Cloud SQL.

On-demand pricing:  n1-standard-4 = ~$0.19/hour
1-year commitment:  n1-standard-4 = ~$0.13/hour  (30% discount)
3-year commitment:  n1-standard-4 = ~$0.08/hour  (57% discount)

2. Spot VMs for Batch Workloads

Spot VMs are excess GCP capacity available at up to 91% discount. GCP can preempt (stop) them with a 30-second warning. Ideal for fault-tolerant batch jobs like data processing and ML training.

Standard VM: e2-standard-4 = $0.134/hour
Spot VM:     e2-standard-4 = ~$0.013/hour  (up to 90% cheaper)

Best for: Dataflow jobs, ML training, video transcoding, rendering
Not for:  Production web servers, databases, stateful applications

3. Right-Sizing Recommendations

GCP analyzes VM usage and recommends downsizing over-provisioned machines. Check Compute Engine → Recommendations for automatic suggestions.

Current:   n2-standard-8  (8 vCPU, 32 GB RAM)  — 95% of time at 5% CPU
Suggested: e2-standard-2  (2 vCPU, 8 GB RAM)   — $87/month savings

4. Cloud Storage Lifecycle Policies

Automatically transition data to cheaper storage classes as it ages:

Standard ($0.020/GB/month) → After 30 days →
Nearline  ($0.010/GB/month) → After 90 days →
Coldline  ($0.004/GB/month) → After 365 days →
Archive   ($0.0012/GB/month) — 83% cheaper than Standard!

5. Delete Unused Resources

Unused ResourceCostAction
Stopped Compute Engine VMStill billed for persistent disk and static IPDelete if no longer needed
Unattached persistent diskBilled at $0.04/GB/monthDelete or snapshot and delete
Reserved static IP (unattached)$7.30/monthRelease if unused
Idle Cloud SQL instanceFull hourly rate even with 0 queriesStop or delete development instances

6. BigQuery Cost Controls

# Always SELECT specific columns (not SELECT *)
-- Expensive: scans all columns (~500 GB)
SELECT * FROM sales_data.orders

-- Cheap: scans only 2 columns (~5 GB)
SELECT order_id, total_amount FROM sales_data.orders

# Set a query cost limit (prevents accidental expensive queries)
# In Console: BigQuery → Settings → Custom quota: 1 TB/day

# Use partitioned tables to limit data scanned
SELECT order_id FROM orders WHERE order_date = '2024-01-15'
-- Only reads 1 partition instead of the entire table ✓

Cloud Billing Export to BigQuery

Detailed billing data can be exported to BigQuery for custom analysis, dashboards, and cost allocation reports.

# Enable billing export: Billing → Billing Export → BigQuery Export
# Once enabled, detailed cost data flows to BigQuery automatically

# Example: Query top 5 costliest services this month
SELECT
  service.description AS service,
  ROUND(SUM(cost), 2) AS total_cost_usd
FROM `my-project.billing_export.gcp_billing_export_v1_*`
WHERE invoice.month = FORMAT_DATE('%Y%m', CURRENT_DATE())
GROUP BY service
ORDER BY total_cost_usd DESC
LIMIT 5;

GCP Pricing Calculator

Before deploying infrastructure, estimate costs at cloud.google.com/products/calculator. Enter the planned configuration (region, machine type, storage size, expected traffic) and the calculator shows the estimated monthly cost.

Key Takeaways

  • GCP uses pay-as-you-go billing with per-second granularity for most services.
  • Budget alerts notify teams before costs exceed defined thresholds — they do not stop resources automatically.
  • Committed Use Discounts provide up to 57% savings for predictable, sustained workloads.
  • Spot VMs reduce compute costs by up to 91% for fault-tolerant batch jobs.
  • Cloud Storage lifecycle policies automatically move data to cheaper classes as it ages.
  • Export billing data to BigQuery for custom cost analysis and chargeback reporting.
  • Regularly delete unused disks, static IPs, and idle Cloud SQL instances to eliminate wasted spend.

Leave a Comment