Skip to content

BigQuery Destinations

Bizon offers three BigQuery destination variants optimized for different workloads.

Terminal window
pip install bizon[bigquery]
VariantMethodBest ForLatency
bigqueryGCS Load JobsLarge batch loadsMinutes
bigquery_streamingLegacy StreamingLow-latency, small volumeSeconds
bigquery_streaming_v2Storage Write APIHigh-throughput streamingSeconds

Uses GCS as a staging area, then loads via BigQuery load jobs. Best for large batch workloads.

destination:
name: bigquery
config:
project_id: my-project
dataset_id: my_dataset
dataset_location: US
create_dataset: true
gcs_buffer_bucket: my-staging-bucket
buffer_size: 50
time_partitioning:
type: DAY
FieldTypeRequiredDefaultDescription
project_idstringYes-GCP project ID
dataset_idstringYes-BigQuery dataset ID
dataset_locationstringNoUSDataset location, used when the dataset is created
create_datasetboolNofalseCreate the dataset if it is missing. When false, a missing dataset fails the run up front
gcs_buffer_bucketstringYes-GCS bucket for staging
gcs_buffer_formatenumNoparquetStaging format. Only parquet is implemented
buffer_sizeintNo50Buffer size in MB
buffer_flush_timeoutintNo600Max buffer age in seconds
time_partitioningobjectNo{type: DAY, field: _bizon_loaded_at}See Time Partitioning
enforce_partitioningboolNofalseOn a full refresh, drop and recreate a table whose partitioning doesn’t match the config. See Changing partitioning
table_prefixstringNo_bizon_Prefix for auto-named tables. See Table Naming
job_timeout_secondsfloatNo600Cancel a load or copy job after this long and fail the stream with a TimeoutError. null waits forever
async_loadboolNofalseSubmit load jobs asynchronously and batch GCS files into fewer jobs
load_files_per_jobintNo10GCS files per load job when async_load is on (min 1)
load_max_in_flight_jobsintNo3Load jobs in flight before the consumer waits, when async_load is on (min 1)

By default each buffer flush uploads one file to GCS and waits for its load job. With async_load: true, flushes upload and submit without blocking, and up to load_files_per_job files share one load job. This raises throughput and cuts the per-table load-job quota usage.

destination:
name: bigquery
config:
project_id: my-project
dataset_id: my_dataset
gcs_buffer_bucket: my-staging-bucket
async_load: true
load_files_per_job: 10
load_max_in_flight_jobs: 3

Delivery stays at-least-once: destination cursors are written in submission order and only once a load lands, and a failed load aborts the run before any later cursor is written. A resumed run re-fetches from the last landed load.

Uses the legacy streaming API. Good for low-latency with moderate volume.

destination:
name: bigquery_streaming
config:
project_id: my-project
dataset_id: my_dataset
dataset_location: US
buffer_size: 50
buffer_flush_timeout: 300
FieldTypeRequiredDefaultDescription
project_idstringYes-GCP project ID
dataset_idstringYes-BigQuery dataset ID
dataset_locationstringNoUSDataset location
buffer_sizeintNo50Buffer size in MB
buffer_flush_timeoutintNo600Max buffer age in seconds
bq_max_rows_per_requestintNo5000Max rows per API call (max 10000)
time_partitioningobjectNo{type: DAY, field: _bizon_loaded_at}See Time Partitioning. null disables partitioning
table_prefixstringNo_bizon_Prefix for auto-named tables

Uses the Storage Write API for high-throughput streaming. Best for production real-time pipelines.

destination:
name: bigquery_streaming_v2
config:
project_id: my-project
dataset_id: my_dataset
dataset_location: US
buffer_size: 100
buffer_flush_timeout: 300
bq_max_rows_per_request: 5000
FieldTypeRequiredDefaultDescription
project_idstringYes-GCP project ID
dataset_idstringYes-BigQuery dataset ID
dataset_locationstringNoUSDataset location
buffer_sizeintNo50Buffer size in MB
buffer_flush_timeoutintNo600Max buffer age in seconds
bq_max_rows_per_requestintNo5000Max rows per API call (max 10000)
time_partitioning.typeenumNoDAYDAY, HOUR, MONTH or YEAR
time_partitioning.fieldstringNo_bizon_loaded_atPartition column. null for ingestion-time partitioning
enforce_partitioningboolNofalseOn a full refresh, drop and recreate a table whose partitioning doesn’t match the config
table_prefixstringNo_bizon_Prefix for auto-named tables

Set time_partitioning: null to create unpartitioned tables.

Provide a service account JSON key:

destination:
name: bigquery_streaming_v2
config:
project_id: my-project
dataset_id: analytics
authentication:
service_account_key: |
{
"type": "service_account",
"project_id": "my-project",
...
}

Or reference it from the environment or a secret manager (see Secrets):

authentication:
service_account_key: ${gsm://bigquery-sa-key}

If running on GCP (GKE, Cloud Run, etc.) or with gcloud auth, omit authentication:

destination:
name: bigquery_streaming_v2
config:
project_id: my-project
dataset_id: analytics

When no destination_id is set, the table is named {table_prefix}{source}_{stream}, so _bizon_hubspot_contacts by default. This applies to all three variants.

  • If the legacy unprefixed table (hubspot_contacts) already exists, bizon keeps writing to it.
  • table_prefix: "" disables the prefix.
  • An explicit destination_id is used as-is and never prefixed.
  • Staging tables (_temp, _incremental) take the resolved name as their base.

Without unnest, every table gets bizon’s metadata columns: _source_record_id, _source_timestamp, _source_data, _bizon_extracted_at, _bizon_loaded_at and _bizon_id. They are all NULLABLE. Load jobs allow field addition and relaxation, so additive schema changes don’t need a migration.

Define schemas for structured loading with unnest: true. The table then holds exactly the columns in record_schema, and none of the metadata columns:

destination:
name: bigquery_streaming_v2
config:
project_id: my-project
dataset_id: analytics
unnest: true
record_schemas:
- destination_id: my-project.analytics.events
record_schema:
- name: event_id
type: STRING
mode: REQUIRED
- name: event_type
type: STRING
mode: REQUIRED
- name: user_id
type: STRING
mode: NULLABLE
- name: payload
type: JSON
mode: NULLABLE
- name: created_at
type: TIMESTAMP
mode: REQUIRED
clustering_keys:
- event_type
- user_id
TypeDescription
STRINGText
INTEGER / INT6464-bit integer
FLOAT / FLOAT6464-bit float
BOOLEANTrue/false
TIMESTAMPDate and time
DATEDate only
DATETIMEDate and time (no timezone)
TIMETime only
JSONJSON object
BYTESBinary data
NUMERIC / BIGNUMERICExact numeric
GEOGRAPHYGeographic data
RECORDNested record
ModeDescription
NULLABLECan be null (default)
REQUIREDCannot be null
REPEATEDArray of values

Route records to different tables based on destination_id:

source:
name: kafka
stream: topic
topics:
- name: user-events
destination_id: my-project.analytics.user_events
- name: order-events
destination_id: my-project.analytics.order_events
destination:
name: bigquery_streaming_v2
config:
project_id: my-project
dataset_id: analytics
unnest: true
record_schemas:
- destination_id: my-project.analytics.user_events
record_schema:
- name: user_id
type: STRING
mode: REQUIRED
- name: action
type: STRING
mode: REQUIRED
- destination_id: my-project.analytics.order_events
record_schema:
- name: order_id
type: STRING
mode: REQUIRED
- name: amount
type: FLOAT64
mode: REQUIRED

All three variants take the same time_partitioning block:

FieldDefaultDescription
typeDAYDAY, HOUR, MONTH or YEAR
field_bizon_loaded_atColumn to partition on. null selects ingestion-time partitioning

A bare time_partitioning: DAY is still accepted and means {type: DAY}. Unknown keys are rejected.

The partition column must be a TIMESTAMP, DATE or DATETIME column of the table, and HOUR is not allowed on a DATE column. On bigquery a bad column fails config validation. On the streaming variants it only fails when bizon creates a new table, and otherwise logs a warning, since BigQuery keeps an existing table’s partitioning anyway.

With unnest: true, _bizon_loaded_at doesn’t exist in the table. If you don’t set field, bizon falls back to ingestion-time partitioning (_PARTITIONDATE) and logs it. To partition on your own column, name it explicitly:

destination:
name: bigquery
config:
project_id: my-project
dataset_id: analytics
gcs_buffer_bucket: my-bucket
time_partitioning:
type: DAY

Changing Partitioning on an Existing Table

Section titled “Changing Partitioning on an Existing Table”

BigQuery cannot repartition a table in place, and publishing into an existing table keeps that table’s spec. Before publishing, bizon compares the staging table’s partitioning with the destination table’s and logs a warning when they differ.

To fix a mismatched table, set enforce_partitioning: true (on bigquery and bigquery_streaming_v2):

  • A full refresh drops the destination table and recreates it with the configured partitioning.
  • An incremental run never drops the table. It warns and points to bizon stream reset, which republishes the stream as a full refresh. See Sync Modes.

Full refresh and incremental runs don’t write to the destination table directly. They stage rows, then publish once the run succeeds:

Sync modeStaging tablePublish
full_refresh{table}_tempReplace the table
incremental{table}_incrementalAppend to the table
streamnoneRows are written to the table directly

On bigquery, publishing is a copy job: WRITE_TRUNCATE for a full refresh, WRITE_APPEND for incremental. Copy jobs are free and metadata-only. On the first incremental run, the copy creates the table with the staging table’s partitioning.

On bigquery_streaming_v2, publishing is a query:

  • Full refresh with a partition column: CREATE OR REPLACE TABLE ... PARTITION BY ... CLUSTER BY ... AS SELECT.
  • Full refresh with ingestion-time partitioning: TRUNCATE then INSERT. This is not atomic: the table is empty between the two statements.
  • Incremental: the table is created if missing, then an INSERT by column name.

The staging table is deleted after publishing. On bigquery, a new full-refresh run also starts by dropping any _temp table left by a crashed run.

A failed write fails the run and nothing is published: a full refresh leaves the previous table intact. On an incremental run, rows already staged in _incremental are published by the next successful run.

bigquery_streaming has no staging table and always appends.

Add clustering keys for better query performance:

record_schemas:
- destination_id: my-project.analytics.events
record_schema:
- name: event_type
type: STRING
mode: REQUIRED
- name: user_id
type: STRING
mode: NULLABLE
clustering_keys:
- event_type
- user_id
┌─────────────────────────────────────────────────────────────┐
│ Is latency critical? │
│ (< 1 minute required) │
└─────────────────────────────┬───────────────────────────────┘
│
┌───────────────┴───────────────┐
│ │
Yes No
│ │
▼ ▼
┌─────────────────────────────┐ ┌──────────────────────────┐
│ Is throughput high? │ │ bigquery │
│ (> 1000 records/sec) │ │ (GCS Load Jobs) │
└──────────────┬──────────────┘ └──────────────────────────┘
│
┌───────────┴───────────┐
│ │
Yes No
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────────┐
│ bigquery_ │ │ bigquery_streaming │
│ streaming_v2 │ │ (Legacy API) │
└─────────────────┘ └─────────────────────┘

Complete production example:

name: kafka-to-bigquery
source:
name: kafka
stream: topic
sync_mode: stream
bootstrap_servers: kafka:9092
message_encoding: utf-8
topics:
- name: events
destination_id: my-project.analytics.events
authentication:
type: basic
params:
username: BIZON_ENV_KAFKA_USER
password: BIZON_ENV_KAFKA_PASSWORD
destination:
name: bigquery_streaming_v2
config:
project_id: my-project
dataset_id: analytics
dataset_location: US
buffer_size: 100
buffer_flush_timeout: 300
bq_max_rows_per_request: 5000
unnest: true
time_partitioning:
type: DAY
field: timestamp
record_schemas:
- destination_id: my-project.analytics.events
record_schema:
- name: event_id
type: STRING
mode: REQUIRED
- name: event_type
type: STRING
mode: REQUIRED
- name: payload
type: JSON
mode: NULLABLE
- name: timestamp
type: TIMESTAMP
mode: REQUIRED
clustering_keys:
- event_type
authentication:
service_account_key: BIZON_ENV_GCP_SERVICE_ACCOUNT
engine:
backend:
type: postgres
config:
host: db.example.com
port: 5432
database: bizon
schema: public
username: bizon
password: ${env://DB_PASSWORD}
runner:
type: stream
log_level: INFO

Run it with the stream runner:

Terminal window
bizon run config.yml --runner stream