Skip to main content
Google Cloud · lesson 10 of 10
Google Cloud advanced Lesson 10 of 10

Also part of: Multi-Cloud

GCP Cost and Billing Basics

Query billing export, skim the Architecture Framework's pillars, and compare On-Demand, Committed Use, and Spot pricing for one machine type, math shown.

By SkillByExample · Published

gcp cost-optimization billing architecture-framework

Cost control on GCP is less about any one setting and more about knowing where to look: billing export for what was actually spent, budgets for getting warned before it goes further, and pricing model choice for what a workload should cost in the first place. This lesson walks all three, ending with real numbers for one machine type.

Billing export to BigQuery

Detailed billing data isn’t queryable through gcloud directly — it has to be exported to BigQuery first.

gcloud billing accounts get-iam-policy 01A2B3-4C5D6E-7F8A9B --format=none  # confirms access
bq query --use_legacy_sql=false '
SELECT
  service.description AS service,
  ROUND(SUM(cost), 2) AS total_cost
FROM `skillbyexample-437219.billing_export.gcp_billing_export_v1_01A2B3_4C5D6E_7F8A9B`
WHERE DATE(usage_start_time) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
GROUP BY service
ORDER BY total_cost DESC
'
+--------------------------+------------+
|          service         | total_cost |
+--------------------------+------------+
| Compute Engine           |      84.32 |
| Cloud SQL                |      41.60 |
| Cloud Storage            |       6.14 |
| Cloud Run                |       0.87 |
+--------------------------+------------+

This is the actual granular source of truth for spend — the Console’s billing overview page summarizes the same underlying export table.

Setting a budget alert

gcloud billing budgets create \
    --billing-account=01A2B3-4C5D6E-7F8A9B \
    --display-name="Monthly project cap" \
    --budget-amount=150.00 \
    --threshold-rule=percent=0.5 \
    --threshold-rule=percent=0.9 \
    --threshold-rule=percent=1.0
Created budget [billingAccounts/01A2B3-4C5D6E-7F8A9B/budgets/a1b2c3d4-e5f6-7890].

Three thresholds fire three separate notifications — at 50%, 90%, and 100% of $150 — to the billing account’s administrators by default. A budget alert never stops a resource from running; it’s purely a notification.

The Architecture Framework’s cost pillar, at a glance

Google’s Architecture Framework reviews a design against five pillars, with sustainability applied as a cross-cutting concern over all of them:

Pillar                            What it asks
---------------------------------------------------------------------------
Operational excellence            Can you deploy, monitor, and run this reliably?
Security, privacy, compliance     Is data and access appropriately protected?
Reliability                       Does it meet its availability target under failure?
Cost optimization                 Is spend proportional to the value delivered?
Performance optimization          Does it meet latency/throughput needs efficiently?

Cost optimization specifically isn’t “spend the least” — it’s matching commitment level and machine shape to actual, measured usage, which is exactly what the next section quantifies.

On-Demand vs Committed Use vs Spot, for one machine type

Comparing n2-standard-4 (4 vCPU, 16 GB memory) in us-central1, published list prices at time of writing:

Pricing model         $/hour     Discount vs On-Demand
---------------------------------------------------------
On-Demand              0.1942     —
1-year Committed Use   0.1223     37%
3-year Committed Use   0.0874     55%
Spot                   0.0463     76%

Extending to a full month (730 hours, the standard GCP billing convention for “a month”):

On-Demand:            0.1942 * 730 = $141.77 / month
1-year Committed Use: 0.1223 * 730 =  $89.28 / month  (save $52.49, 37.0%)
3-year Committed Use: 0.0874 * 730 =  $63.80 / month  (save $77.97, 55.0%)
Spot:                 0.0463 * 730 =  $33.80 / month  (save $107.97, 76.2%)

The catch scales with the discount. A 1-year CUD bills $89.28 every month for 12 months regardless of whether the VM runs the full month or sits idle — committing a workload that actually only runs half the month would make the “discount” cost more than On-Demand billed for actual usage ($70.89). Spot is the cheapest by far, but Google can reclaim a Spot instance with 30 seconds’ notice, which rules it out for anything that isn’t fault-tolerant and checkpointable.

Choose On-Demand         for short-lived or unpredictable workloads
Choose Committed Use     for a proven, steady-state baseline you'll run 12-36 months regardless
Choose Spot              for fault-tolerant batch jobs that can restart cleanly

Practice

1. Calculate the break-even utilization for the 1-year CUD versus paying On-Demand only while running.
CUD monthly cost:  $89.28 (fixed, regardless of usage)
On-Demand cost per hour of actual use: $0.1942
Break-even hours:  89.28 / 0.1942 = 459.7 hours

459.7 / 730 = 63.0% utilization

Below 63% utilization in a month, paying On-Demand only for the hours actually used is cheaper than committing to the 1-year discount — the CUD only pays off past that line.

2. Query billing export for cost broken down by label instead of by service.
bq query --use_legacy_sql=false '
SELECT
  (SELECT value FROM UNNEST(labels) WHERE key = "env") AS environment,
  ROUND(SUM(cost), 2) AS total_cost
FROM `skillbyexample-437219.billing_export.gcp_billing_export_v1_01A2B3_4C5D6E_7F8A9B`
WHERE DATE(usage_start_time) >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY)
GROUP BY environment
'
+-------------+------------+
| environment | total_cost |
+-------------+------------+
| production  |     102.44 |
| staging     |      21.90 |
| NULL        |       7.99 |
+-------------+------------+

The NULL row is resources with no env label at all — a common finding the first time anyone runs this query, and usually the argument for a label-enforcement policy.

3. List existing budgets and check which one is closest to its threshold.
gcloud billing budgets list --billing-account=01A2B3-4C5D6E-7F8A9B \
    --format="table(displayName,amount.specifiedAmount.units)"
DISPLAY_NAME            UNITS
Monthly project cap     150

gcloud reports the budget’s configuration, not live spend against it — actual percent-consumed requires the billing export query from the first example, filtered to the current month.

4. Recompute the comparison table for e2-standard-4 instead of n2-standard-4, using its lower on-demand rate of $0.1611/hour and the same discount percentages.
On-Demand:            0.1611 * 730 = $117.60 / month
1-year Committed Use: 0.1015 * 730 =  $74.10 / month
3-year Committed Use: 0.0725 * 730 =  $52.93 / month
Spot:                 0.0384 * 730 =  $28.03 / month

The percentage savings carry over almost exactly across machine families because CUD and Spot discounts are applied as a rate off whatever the on-demand price is, not a flat dollar amount.

5. Delete the budget created earlier.
gcloud billing budgets delete billingAccounts/01A2B3-4C5D6E-7F8A9B/budgets/a1b2c3d4-e5f6-7890 --quiet
Deleted budget [billingAccounts/01A2B3-4C5D6E-7F8A9B/budgets/a1b2c3d4-e5f6-7890].

Deleting a budget only removes the alert — it has no effect on any resource or on spend that already happened.

This closes the GCP track. Between the free-tier credit from the first lesson and Spot pricing from this one, every example here can be rerun for well under a dollar.

Frequently Asked Questions

What's the difference between a budget and a billing export in GCP?
A budget is an alert — it watches actual or forecasted spend against a threshold you set and notifies you when crossed, but it can't stop spending on its own. Billing export streams every line item to BigQuery for arbitrary querying — cost by service, by label, by project — which a budget alert alone can't answer.
What are the pillars of the Google Cloud Architecture Framework?
Operational excellence, security/privacy/compliance, reliability, cost optimization, and performance optimization, with sustainability treated as a cross-cutting perspective applied across all five. Each pillar is a lens for reviewing a design, not a separate product — the same architecture gets evaluated against all of them.
Is a Committed Use Discount the same as a reservation?
No, though they're often paired. A Committed Use Discount (CUD) is a billing commitment — you promise a spend level for 1 or 3 years in exchange for a lower rate — while a reservation guarantees physical capacity will be available. You can commit to a discount without reserving capacity, or reserve capacity at on-demand rates without any discount.
How much cheaper is a Spot VM really, and what's the catch?
Spot VMs price at a steep discount off on-demand — often 60-90% depending on machine type and region — because Google can reclaim the capacity with only a 30-second warning whenever it's needed elsewhere. That makes Spot suitable for fault-tolerant batch work and unsuitable for anything that can't checkpoint or restart cleanly.
If Committed Use Discounts are cheaper than on-demand, why doesn't everyone commit to everything?
A CUD bills the committed amount whether or not you actually use it — it's a discount on a promise, not a discount on usage. Committing above your steady-state baseline turns unused capacity into pure waste, which is why CUDs are sized against a workload's proven floor, not its peak or its hoped-for growth.