Skip to content
Back to skills

Gcp Bigquery

ASecurity

Use when the user asks about BigQuery cost, bytes scanned, partitioning and clustering, slots and editions, slow BigQuery queries, or Dremel and Capacitor internals. Produces table designs, query fixes and a pricing-model choice. Not for warehouse vendor comparison (use data-data-warehouse) or dbt projects (use data-science-analytics-engineering).

  • 46 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 27, 2026
ai-agentsgosqlgcpapidevopssecurity

Works with

  • api

Security analysis

A100/100

Scanned November 27, 2026

npx -y skills add j4flmao/agent-skills --skill gcp-bigquery --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Gcp Bigquery?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Gcp Bigquery
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/j4flmao-gcp-bigquery/badge)](https://www.skillsdirectory.com/skills/j4flmao-gcp-bigquery)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cloud-native-gcp-bigquery
description: >
  Use when the user asks about BigQuery cost, bytes scanned, partitioning and clustering, slots and editions, slow BigQuery queries, or Dremel and Capacitor internals. Produces table designs, query fixes and a pricing-model choice. Not for warehouse vendor comparison (use data-data-warehouse) or dbt projects (use data-science-analytics-engineering).
version: "2.0.0"
author: "j4flmao"
license: "MIT"
last_verified: "2026-11-17"
tags: [cloud-native, gcp, bigquery, dremel, data-warehouse, cost-optimization]
---

# GCP BigQuery Internals and Optimization

## Purpose
BigQuery cost and speed are determined by bytes read and slot time. Knowing how Dremel distributes work and how Capacitor stores columns explains why partitioning, clustering, and column selection matter more than anything else.

## Agent Protocol

### Trigger
"bigquery", "bigquery cost", "partitioning", "clustering", "dremel", "capacitor", "slots", "editions", "slow query", "bytes scanned".

### Input Context
- Table sizes, query patterns (filters, joins, time ranges).
- Pricing model in use (on-demand vs editions reservations).
- Freshness/streaming needs.

### Output Artifact
DDL, rewritten SQL, or reservation plan. No file unless requested.

### Response Format
```
Problem: {bytes scanned|slot contention|shuffle/skew|streaming cost}
Change: {DDL/SQL}
Expected effect: {partitions pruned / columns avoided}
Verify with: {dry run bytes, INFORMATION_SCHEMA.JOBS}
```

### Completion Criteria
- [ ] Large tables partitioned on the dominant filter column and clustered on secondary filters.
- [ ] Cost verified with a dry run or `INFORMATION_SCHEMA.JOBS`, not estimated.

## Architecture
- **Storage/compute separation.** Data lives in Colossus (Google's distributed file system) in the **Capacitor** columnar format; compute is allocated per query as **slots** (units of CPU/RAM/network).
- **Dremel execution.** A query becomes a multi-stage plan; stages run in parallel on slots, reading only the referenced columns. Intermediate results are exchanged through a distributed in-memory **shuffle** tier, which lets stages scale independently.
- **Capacitor** stores each column separately with encodings (dictionary, run-length, etc.) and per-block metadata (e.g. min/max) used to skip blocks — the basis of clustering's block pruning.
- **Network.** Jupiter datacenter network lets workers read storage at high bandwidth, so compute does not need to be co-located with data.

```mermaid
flowchart LR
  Q[SQL] --> P[Query planner]
  P --> S1[Stage 1: scan + filter on slots]
  S1 --> SH[(Distributed shuffle)]
  SH --> S2[Stage 2: join / aggregate]
  S2 --> R[Result]
  S1 -.reads columns.-> C[(Capacitor files on Colossus)]
```

## Pricing Models
| Model | You pay for | Fit |
|---|---|---|
| On-demand | Bytes processed per query (logical bytes; first 1 TiB/month free) | Spiky, small/medium usage |
| Editions (Standard, Enterprise, Enterprise Plus) | Slot-hours via reservations with autoscaling (optional baseline / commitments) | Predictable heavy usage, workload isolation |
| Storage | Logical or physical (compressed) bytes, chosen per dataset; long-term rate after 90 days unmodified | Physical billing often cheaper for well-compressed data |

On-demand queries are capped by a per-project concurrent slot quota; heavy concurrency is the usual reason to move to reservations.

## Table Design

```sql
CREATE TABLE analytics.events
(
  event_ts    TIMESTAMP NOT NULL,
  customer_id STRING,
  event_type  STRING,
  country     STRING,
  payload     JSON
)
PARTITION BY DATE(event_ts)
CLUSTER BY customer_id, event_type
OPTIONS (
  require_partition_filter = TRUE,
  partition_expiration_days = 400
);
```
- Partition on a DATE/TIMESTAMP/DATETIME column (time-unit), ingestion time, or integer range. Limit: 10,000 partitions per table — use monthly partitions for long histories at daily granularity.
- Cluster on up to 4 columns, ordered by filter frequency; clustering helps equality/range filters and aggregations on those columns. BigQuery re-clusters automatically in the background at no charge.
- Partitioning gives an accurate dry-run cost estimate; clustering savings appear only at execution.

## Query Tuning Rules
| Symptom | Cause | Fix |
|---|---|---|
| Huge bytes billed | `SELECT *`, no partition filter | Select needed columns; filter on partition column directly (not wrapped in functions of other columns) |
| `LIMIT` didn't reduce cost | LIMIT applies after the scan | Filter instead; use table preview for sampling |
| Slow join, "skew" in plan | One key with massive row count | Pre-aggregate, filter nulls/hot keys, or split hot key |
| Repeated identical dashboards | Recomputing aggregates | Materialized views, BI Engine, or scheduled aggregate tables |
| Subquery re-evaluated | Non-deterministic or complex CTE used multiple times | Materialize to a temp table in a multi-statement query |
| `ORDER BY` on large result fails | Final sort on single worker | Add `LIMIT` with ORDER BY, or sort downstream |

Inspect cost:
```sql
SELECT user_email, query, total_bytes_billed / POW(1024, 4) AS tib_billed, total_slot_ms
FROM `region-eu`.INFORMATION_SCHEMA.JOBS
WHERE creation_time > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
  AND job_type = 'QUERY'
ORDER BY total_bytes_billed DESC
LIMIT 20;
```
Dry run: `bq query --use_legacy_sql=false --dry_run 'SELECT ...'`.

## Ingestion
- Batch loads (`bq load`, load jobs from GCS) are free of ingestion charges (shared slot pool).
- Streaming: use the **Storage Write API** (exactly-once with committed streams, cheaper than legacy `insertAll`).
- CDC into BigQuery: Datastream, or Storage Write API with `_CHANGE_TYPE` upserts on tables with primary keys.

## Anti-Patterns
- Date-sharded tables (`events_20250101`) instead of partitioned tables.
- Oversharding partitions (hourly partitions for small tables) — partitions < ~1 GB gain little.
- Using BigQuery as an OLTP store (single-row updates, high-frequency DML) — DML quotas and cost.
- Granting `bigquery.admin` broadly; use dataset/table IAM and authorized views or row-level security.
- Custom quotas absent → a single runaway on-demand query can bill tens of TiB.

## Checklist
- [ ] Partition + cluster large fact tables; `require_partition_filter` on.
- [ ] Custom per-user/per-project daily query quotas set.
- [ ] Top queries reviewed weekly via `INFORMATION_SCHEMA.JOBS`.
- [ ] Storage billing model evaluated (logical vs physical).
- [ ] Reservations sized from historical slot usage before switching to editions.

## References
- Related skills: `skills/devops/gcp/SKILL.md`, `skills/devops/finops/SKILL.md`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.