🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

ELT Pipeline Patterns: GCS → BigQuery, External Tables & Materialized Views

GCP Data EngineeringELT Pipelines🟢 Free Lesson

ELT Pipeline Patterns on GCP

Master ELT patterns including GCS to BigQuery loading, external tables, materialized views, and dbt integration on GCP.

18 min readAdvanced

What You'll Learn

  • 1Justify loading raw data first using BigQuery's storage and compute split
  • 2Choose between an external table, a load job and a streaming write
  • 3Explain when a materialized view will be rewritten and when it will not
  • 4Structure dbt models and tests so ELT changes ship like application code

Why Loading First Wins on BigQuery

ELT reverses the middle two letters because the target engine is unusually good at transformation: storage is measured in cents per GB-month, compute scales in slots that can burst, and every transformation is a SQL statement that can be rerun against the same raw input. Landing raw data first therefore buys three things. Reprocessing is free in the sense that no second copy of the source is needed when a rule changes. Lineage is trivial to reason about, because each model is a query over the models below it rather than an opaque job that produced a table nobody can rebuild. And the transformation work happens in the engine where the data already lives, so nothing crosses a network boundary twice.

The honest cost of that decision is governance and disk. Raw layers hold data that has not been filtered, so the identifiers sitting in a source export are now replicated into your warehouse until a model removes them, which means access control on the raw dataset cannot be an afterthought. And an unmaintained raw layer grows without bound, so expiration policies on bronze partitions are part of the design rather than a cleanup chore. Teams that get ELT wrong usually get one of those two things wrong, not the SQL.

Landing Data: Three Write Paths

-- External table: query files without copying them
CREATE OR REPLACE EXTERNAL TABLE `project.bronze.sales_external`
OPTIONS (
  format = 'PARQUET',
  uris = ['gs://my-data-lake/bronze/sales/**/*.parquet']
);

-- External table over compressed JSON, tolerating a few bad records
CREATE OR REPLACE EXTERNAL TABLE `project.bronze.events_external`
OPTIONS (
  format = 'JSON',
  uris = ['gs://my-data-lake/bronze/events/*.json.gz'],
  max_bad_records = 100
);

-- Query it exactly like a native table
SELECT
  product_category,
  SUM(amount) AS total_revenue
FROM `project.bronze.sales_external`
WHERE order_date >= '2025-01-01'
GROUP BY 1;
python
from google.cloud import bigquery

client = bigquery.Client()

job_config = bigquery.LoadJobConfig(
    source_format=bigquery.SourceFormat.CSV,
    skip_leading_rows=1,
    autodetect=True,
    write_disposition=bigquery.WriteDisposition.WRITE_TRUNCATE,
    time_partitioning=bigquery.TimePartitioning(
        type_=bigquery.TimePartitioningType.DAY,
        field="order_date"
    ),
    clustering_fields=["product_category", "region"]
)

load_job = client.load_table_from_uri(
    'gs://my-data-lake/bronze/sales/*.csv',
    'project.bronze.sales',
    job_config=job_config
)

load_job.result()
print(f"Loaded {load_job.output_rows} rows")

The three write paths answer different questions. An external table costs nothing to create and bills only when queried, which makes it the correct first landing for a prefix you are exploring. A load job copies bytes into BigQuery, supports partitioning and clustering at the moment of ingest, and is where a table becomes cheap to query repeatedly. Streaming through Pub/Sub and the Storage Write API is reserved for data that must be visible within seconds, because it carries the streaming buffer and partition constraints that batch loads avoid entirely. A common mistake is letting autodetect define a production schema, since it infers from the sampled files and will happily read an identifier column as INTEGER on the first thousand rows and fail at row ten million; declare the schema explicitly once the shape is known.

Materialized Views and the Rewrite You Get for Free

A materialized view stores the result of a query and refreshes incrementally as the base tables change, so the aggregation cost is paid once per change rather than once per dashboard load. Its most valuable property is automatic rewrite: a query that the view can satisfy is redirected to it without the dashboard author changing anything.

CREATE MATERIALIZED VIEW `project.analytics.sales_summary_mv`
PARTITION BY DATE(order_date)
CLUSTER BY product_category
AS
SELECT
  DATE(order_date) AS order_date,
  product_category,
  COUNT(*) AS order_count,
  SUM(amount) AS total_revenue,
  AVG(amount) AS avg_order_value,
  COUNT(DISTINCT customer_id) AS unique_customers
FROM `project.bronze.sales`
WHERE status = 'completed'
GROUP BY 1, 2;

-- Force a rebuild after a backfill
ALTER MATERIALIZED VIEW `project.analytics.sales_summary_mv` REFRESH;

Rewrite is conditional and worth understanding precisely. The query must be able to derive its result from the view's columns and grouping, the filter and join predicates must be compatible, and if the base table requires a partition filter the view carries the same requirement. When any condition fails the planner silently falls back to the base tables and the cost returns, which is why the bytes processed column in job statistics is the only reliable way to confirm the view is earning its storage. Use them for aggregations that repeat and are expensive to recompute; do not materialise a filter over a table that already prunes to one partition, because you would pay storage to save almost nothing.

dbt and Version-Controlled Transformation

dbt turns the transformation layer into a codebase: SQL models with dependencies, Jinja for reuse, materialisation declared per model, tests attached to the schema, and documentation generated from the same file.

-- models/stg_sales.sql
WITH source AS (
    SELECT * FROM {{ source('bronze', 'sales') }}
),

transformed AS (
    SELECT
        order_id,
        customer_id,
        product_category,
        amount,
        order_date,
        CURRENT_TIMESTAMP() AS loaded_at
    FROM source
    WHERE amount > 0
)

SELECT * FROM transformed
# models/schema.yml
version: 2
models:
  - name: stg_sales
    description: "Staged sales data"
    columns:
      - name: order_id
        description: "Primary key"
        tests:
          - unique
          - not_null
      - name: amount
        description: "Order amount"
        tests:
          - not_null
          - dbt_utils.accepted_range:
              min_value: 0

The materialisation choice is where cost and correctness meet, and each model should declare it deliberately.

MaterialisationWhat dbt createsCost profileUse for
ephemeralA common table expressionNoneSmall intermediates reused a few times
viewA BigQuery viewFree to create, billed per queryLight transforms read rarely
tableA physical tableStorage plus load jobHeavy joins read many times
incrementalA table updated by a mergeBounded reprocess per runLarge facts that only append or change
materialized viewA BigQuery materialized viewStorage plus refreshAggregations behind dashboards

An incremental model needs a predicate, usually on an ingestion timestamp or an event date, that bounds what each run touches, and it must handle late arriving rows with either a lookback window or a merge on the business key. Without that, incremental models quietly miss data and the tests stay green because they only check what arrived.

The Cost Model of Each Pattern

Every ELT pattern has a different bill, and the right choice changes as a query repeats. An external table has no storage cost and bills for bytes processed on each query, so it is cheapest for the first few reads and worst for a dashboard that runs hourly. A physical table costs storage at roughly two cents per GB-month and bills for the columns scanned, which is far cheaper once the same data is read more than a handful of times. A materialized view adds refresh compute and storage but removes repeated aggregation work. On demand queries cost five dollars per TiB scanned, so a wide SELECT * across a partitioned table is the single most common source of an unexpected bill, and the guard is a maximum bytes billed on ad hoc projects plus partition and cluster filters that make a full scan impossible.

Slot reservations are the other half. Predictable scheduled transformations fit a reserved pool with a floor and an autoscaling ceiling, which is cheaper than paying the on demand rate for work you can forecast, while exploratory analyst queries stay on demand with the bytes cap. The pattern that works is to measure bytes scanned by query from INFORMATION_SCHEMA.JOBS for a month, then move only the stable top consumers onto reservations.

✨

Best Practice: Declare production schemas explicitly instead of relying on autodetect, land files as external tables for exploration and load them once a query pattern repeats, and materialise only aggregations that are expensive to reprocess. Confirm materialized view rewrites in job statistics, and bound every incremental model with a predicate plus a merge so late data cannot slip through.

Common Interview Questions

Q1: ETL or ELT?

Answer: ETL transforms before loading, which suits masking before a shared target or a hard target contract. ELT loads raw and transforms in place, which suits BigQuery because storage is cheap, compute scales on demand, and every transformation is a rerunnable query with clear lineage.

Q2: External table or physical table?

Answer: External while you are exploring or reading rarely, because there is no storage charge and creation is instant. Physical once the same data is read repeatedly, because a scan billed every time exceeds the two cents per GB-month of storage after a few reads, and because physical tables support clustering and expiration.

Q3: How do materialized views improve performance?

Answer: They precompute and store results and refresh incrementally as base rows change, and BigQuery rewrites compatible queries to read them automatically. The caveat is that incompatible predicates silently fall back to base tables, so bytes processed in job statistics is how you verify they are in use.

Q4: How does dbt fit into a BigQuery ELT pipeline?

Answer: It compiles SQL models into a dependency graph, runs them in order with a declared materialisation per model, attaches tests and documentation to the same files, and exposes the whole thing to continuous integration so transformation changes ship with reviews and rollbacks like any other code.

Q5: What are the cost implications of each pattern?

Answer: External tables bill per byte scanned with no storage; physical tables bill storage plus scanned columns; materialized views add refresh and storage while cutting repeated aggregation; on-demand queries cost five dollars per TiB, so partition filters, clustering, a bytes cap and reservations for the steady workload are the four levers that matter.

Interview Questions

Q1: Why is autodetect dangerous on a production load?

It infers types from the sampled files, so an identifier that looks numeric in the first rows becomes INT64 and the job fails or silently loses precision later; declare the schema once the shape is stable.

Q2: What makes an incremental dbt model correct?

A predicate that bounds each run plus a merge or lookback that catches late arriving rows, so the table converges on the truth instead of only containing what happened to arrive on time.

Q3: When will BigQuery not rewrite a query to a materialized view?

When the query needs a column or join key the view does not contain, or applies a filter the view cannot derive, in which case the planner reads base tables and the cost returns without any error.

Q4: How do you decide what to move onto reserved slots?

Rank queries by bytes and slot hours in INFORMATION_SCHEMA.JOBS over a month, then reserve only the stable scheduled consumers; exploratory work stays on demand under a maximum bytes billed cap.

Common Mistakes

Letting autodetect define the production schema

Fix: Declare the schema explicitly in the load job so a type change in a source file becomes a visible error rather than a silent truncation.

Materialising every model in dbt

Fix: Use views for light rarely read transforms and reserve tables and incremental models for heavy ones, because each table costs storage and a load job on every run.

Assuming a materialized view is always being used

Fix: Check total_bytes_processed in job statistics after the rewrite; incompatible predicates fall back to base tables with no warning.

Key Takeaways

  • ELT loads raw first so transformations are rerunnable SQL with obvious lineage, at the cost of governing an unfiltered raw layer
  • External tables cost nothing to store and everything to scan repeatedly, so a query pattern that repeats should become a partitioned physical table
  • Materialized views refresh incrementally and are used only when the planner can rewrite the query, which job statistics will confirm
  • dbt makes the transformation layer reviewable: models declare their materialisation, tests attach to columns, and incremental models need an explicit bound
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert GCP Data Engineering Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement