Cloud · GCP in Depth

Cost governance in GCP: BigQuery queries and storage

gcpMediumgcpbigquerycost-optimizationgovernancestorage

Interview question

How do you protect your team from unexpected BigQuery and Cloud Storage bills?

How to answer

The short answer

BigQuery on-demand pricing charges $6.25 per terabyte of data scanned. Without architectural guardrails, an accidental query scanning multi-terabyte tables can incur hundreds of dollars in seconds.

BigQuery query cost controls

Data teams implement several native controls to protect against runaway query costs:

  • Maximum bytes billed: Set the maximum_bytes_billed limit in query job options or custom scripts. If a query estimated scan size exceeds this limit, BigQuery fails the job before scanning any data.
  • Require filter: Enable the require_partition_filter = true table setting on large partitioned tables. Queries against the table fail immediately if the query omits a partition filter in the WHERE clause.
  • Dry run estimations: Run queries with the dry_run = True flag in client code to determine exact bytes scanned without running the query or incurring costs.
  • Editions and reservations: Switch from on-demand billing to BigQuery Editions (Standard or Enterprise) with autoscaling slot reservations for predictable baseline monthly expenses.
Output
BigQuery Table Setting:   require_partition_filter = true (Forces WHERE clause)
Client Query Options:     maximum_bytes_billed = 50 GB   (Rejects giant scans)
Dry Run Verification:     dry_run = True (Calculates cost with $0 spent)
Cloud Storage Autoclass:  Auto-moves idle objects to Nearline / Coldline

Storage tiering with Autoclass

Cloud Storage allows teams to enable Autoclass, an automated feature that transitions objects to Nearline, Coldline, and Archive classes based on access history without writing custom lifecycle rules.