One Table, Many Engines: Running BigQuery, Spark, and Trino on a Single Iceberg Copy
Introduction
When a data platform serves analysts, data‑science teams, and operational pipelines, it is tempting to give each workload its own “copy” of the source table. BigQuery can read Parquet files stored in Cloud Storage, Spark can materialize transformations in its own directories, and Trino can surface the same data through a separate catalog. The result looks tidy at first—each engine has a clean, isolated view of the data it needs.
But the hidden cost of this approach quickly becomes clear. Sync jobs that copy rows from one system to another never finish instantly, so a “shipped” order may appear as “paid” in Spark while BigQuery still shows “pending”. The lag creates trust issues, and the multiple copies inflate storage bills and operational overhead. Engineers spend cycles debugging why the three views diverge, and the platform ends up paying for compute (the sync jobs) and storage (the duplicate files) that could have been avoided.
The solution is to let all three engines read and write a single, canonical Iceberg table that lives in a shared Cloud Storage bucket and is governed by a Lakehouse runtime catalog. For a broader comparison of how Iceberg stacks against alternatives, read our Apache Iceberg vs. Delta Lake vs. Apache Hudi: 2026-2027 Matrix. Iceberg’s metadata files and commit protocol guarantee that every engine sees the same snapshot of the table, even when two writers attempt to change it at the same time. The pattern—one table, many engines—eliminates copy‑jobs, reduces latency, and consolidates governance under a single catalog.
Below is a practical guide that shows how to set up this architecture in Google Cloud, step‑by‑step, and then adds Dataspanner’s engineering perspective on when this pattern shines and when it may be overkill.
1. Architecture Overview
At the heart of the design is a single Cloud Storage bucket that holds the Parquet data files and the Iceberg metadata (metadata.json). The bucket is not directly accessible to the workloads; instead, a Lakehouse runtime catalog (a multi‑bucket catalog of type CATALOG_TYPE_BIGLAKE) holds a pointer to the latest metadata version.
+-------------------+ +-------------------+ +-------------------+
| Cloud Storage | | Lakehouse | | Multiple Engines|
| Bucket (gs://) |<-------->| Runtime Catalog |<-------->| (BigQuery, Spark,|
| | pointer | (projects/... ) | pointer | Trino) |
+-------------------+ +-------------------+ +-------------------+
^ ^ ^
| | |
Table metadata.json Table metadata.json Table metadata.json
| | |
Parquet files Parquet files Parquet files
BigQuery uses the four‑part name
project.catalog.namespace.table(P‑C‑N‑T) and connects automatically because the catalog is exposed via the REST endpointhttps://biglake.googleapis.com/iceberg/v1/restcatalog. No connector installation is needed.Apache Spark (Managed Service for Apache Spark) registers the catalog through the
spark.sql.catalog.<catalog_id>property, which points to the same REST catalog. The Spark warehouse is set tobl://projects/<project>/catalogs/<catalog_id>so that writes land in the shared bucket.Trino runs as an optional component on the same Spark cluster. It also talks to the REST catalog via the
trino.catalog.type=icebergconfiguration, using the same four‑part name.
Because the catalog vends credentials to a single service account, only that identity needs roles/storage.objectUser on the bucket. All three engines authenticate with their own identities, and the catalog issues short‑lived tokens scoped to the exact table path. This design keeps security tight while allowing each engine to operate independently.
2. Step‑by‑Step Implementation
The following sections walk through the entire lifecycle: bucket creation, catalog provisioning, Spark cluster launch, table creation, and concurrent writes from each engine. All commands are written for a fresh Google Cloud project; replace my-project and us‑central1 as needed.
2.1 Create the Storage Bucket
# Variables – keep them consistent across the script
export PROJECT_ID="my-project"
export REGION="us-central1"
export BUCKET_NAME="${PROJECT_ID}-lakehouse-demo"
export CATALOG_ID="one_table_catalog"
# Create a bucket with uniform bucket‑level access (recommended for security)
gcloud storage buckets create gs://${BUCKET_NAME} \
--project=${PROJECT_ID} \
--location=${REGION} \
--uniform-bucket-level-access
The bucket is the single data store. No data lives directly in the bucket besides Parquet files and Iceberg metadata; the catalog never stores rows.
2.2 Provision the Lakehouse Runtime Catalog
# Create a multi‑bucket catalog of type BIGLAKE.
gcloud biglake iceberg catalogs create ${CATALOG_ID} \
--project=${PROJECT_ID} \
--catalog-type=biglake \
--default-location=gs://${BUCKET_NAME} \
--credential-mode=vended-credentials
--catalog-type=biglake tells the service to manage a multi‑bucket catalog rather than a single‑bucket one. This is essential because BigQuery expects a catalog that can be referenced via the REST endpoint, not a bucket‑named catalog.
The command creates a dedicated service account (biglake-service-account). In credential‑vending mode, this account is the only principal that receives direct read/write permission on the bucket.
# Retrieve the service account and grant it object‑user rights.
CATALOG_SA=$(gcloud biglake iceberg catalogs describe ${CATALOG_ID} \
--project=${PROJECT_ID} \
--format='value(biglake-service-account)')
gcloud storage buckets add-iam-policy-binding gs://${BUCKET_NAME} \
--member="serviceAccount:${CATALOG_SA}" \
--role="roles/storage.objectUser"
If the grant fails immediately, wait ~20 seconds and retry. The repository’s script wraps this in a loop for safety.
2.3 Launch a Managed Spark Cluster with Trino
gcloud dataproc clusters create lakehouse-demo \
--project=${PROJECT_ID} \
--region=${REGION} \
--zone=${REGION}-a \
--image-version=2.3-debian12 \
--optional-components=ICEBERG,TRINO \
--enable-component-gateway \
--master-machine-type=n2-standard-4 \
--worker-machine-type=n2-standard-4 \
--num-workers=2 \
--properties="dataproc:dataproc.lakehouse.catalog.${CATALOG_ID}=projects/${PROJECT_ID}/catalogs/${CATALOG_ID}"
A few notes:
- The
ICEBERGandTRINOoptional components install the Iceberg runtime and Trino server on the same cluster, allowing Spark and Trino to share the same catalog without extra network hops. - The
dataproc.lakehouse.catalog.<catalog_id>property wires Spark to the REST catalog. - The cluster’s default service account needs
roles/dataproc.workerandroles/biglake.editor(the latter lets Spark create Iceberg tables) androles/serviceusage.serviceUsageConsumer(to call the BigLake API).
2.4 Define the Namespace and Create the Iceberg Table
Inside the Spark REPL (or a Spark notebook) run the following DDL. The ORDERED layout is chosen because the table will receive frequent updates and deletes (MERGE statements) from BigQuery.
-- Create the namespace (catalog.namespace)
CREATE NAMESPACE IF NOT EXISTS ${CATALOG_ID}.shop;
-- Define the schema – adjust types as needed
CREATE TABLE ${CATALOG_ID}.shop.orders (
order_id BIGINT,
customer_id BIGINT,
status STRING,
amount DECIMAL(10,2),
updated_at TIMESTAMP
)
USING ICEBERG
PARTITIONED BY (date(updated_at) AS order_date)
TBLPROPERTIES (
'iceberg.write.format.default'='parquet',
'iceberg.compress.default'='zstd'
);
PARTITIONED BYis optional but demonstrates how Iceberg can add a hidden partition column without extra files.- The
TBLPROPERTIESensure that writes produce Parquet files with Zstd compression, which balances size and read performance.
2.5 Populate Initial Data with Spark
INSERT INTO ${CATALOG_ID}.shop.orders VALUES
(1, 100, 'paid', 250.00, TIMESTAMP('2025-10-01 09:00:00')),
(2, 101, 'shipped', 120.00, TIMESTAMP('2025-10-01 10:30:00'));
After the insert, you can verify the table’s snapshot via the catalog API or by querying with Trino.
2.6 Append Data Using Trino
Trino connects to the same catalog using the four‑part name. In a Trino CLI session (or a notebook) run:
INSERT INTO my-project.one_table_catalog.shop.orders
SELECT
3 AS order_id,
102 AS customer_id,
'pending' AS status,
85.50 AS amount,
CURRENT_TIMESTAMP AS updated_at;
Because Trino writes through the Iceberg REST catalog, the commit is recorded in the shared metadata.json. No separate copy is created.
2.7 Perform Upserts with BigQuery
BigQuery does not need any special connector; it simply reads the Iceberg table as if it were a regular external table. The query below updates the status of order 1 and inserts a new row for order 4.
WITH source AS (
SELECT
order_id,
customer_id,
status,
amount,
CURRENT_TIMESTAMP() AS updated_at
FROM `my-project.one_table_catalog.shop.orders`
WHERE order_id IN (1, 4)
)
MERGE INTO `my-project.one_table_catalog.shop.orders` AS target
USING source AS src
ON target.order_id = src.order_id
WHEN MATCHED THEN
UPDATE SET
target.customer_id = src.customer_id,
target.status = src.status,
target.amount = src.amount,
target.updated_at = src.updated_at
WHEN NOT MATCHED THEN
INSERT (order_id, customer_id, status, amount, updated_at)
VALUES (src.order_id, src.customer_id, src.status, src.amount, src.updated_at);
BigQuery’s MERGE translates to an Iceberg replace operation, which writes new Parquet files and updates the metadata pointer atomically.
2.8 Simulate Concurrent Writes
To see Iceberg’s conflict resolution in action, open two Spark sessions (or two Trino sessions) and issue an INSERT that targets the same logical partition at the same time. Iceberg will serialize the commits based on the snapshot timestamp and sequence number stored in the metadata. The first writer wins; the second receives a clear error indicating that the table has been modified and can be retried with a fresh snapshot.
A simple script to reproduce this looks like:
# In two separate Python shells connected to the same Spark cluster
from pyspark.sql import SparkSession
spark = SparkSession.builder.appName("concurrent").getOrCreate()
# Both sessions run the same INSERT
spark.sql(f"INSERT INTO ${CATALOG_ID}.shop.orders SELECT 99, 999, 'test', 0.0, TIMESTAMP('2025-10-01 12:00:00')")
The logs will show something like:
[INFO] IcebergException: Table shop.orders was updated concurrently; please retry the operation.
Iceberg’s optimistic concurrency control guarantees that no two snapshots overwrite each other, preserving data integrity across engines.
3. Concurrency & Conflict Handling
Iceberg’s commit protocol works like a single‑writer queue even when multiple processes issue writes. Each writer reads the current metadata.json, creates a new metadata version, and attempts to atomically replace the pointer in the catalog. If two writers read the same metadata at the same instant, they each generate a new version with a different snapshot ID. When the first writer succeeds, the second’s attempt to replace the pointer fails because the catalog now points to a newer metadata file.
Key points for engineers:
| Aspect | What It Means | Practical Impact |
|---|---|---|
| Snapshot Isolation | Every query reads from a consistent point-in-time snapshot. | Readers never see partial writes or uncommitted transactions. |
| Optimistic Concurrency | Writers validate that table metadata has not changed before committing. | High write throughput with automatic retries on commit collisions. |
| Atomic Metadata Updates | The catalog pointer switches atomically from one metadata file to the next. | Engines always access a deterministic table state. |
Frequently Asked Questions
Can BigQuery and Spark safely write to the same Apache Iceberg table simultaneously?
Yes, provided both engines share a centralized Iceberg catalog (such as Apache Polaris, Project Nessie, or BigQuery BigLake Metastore). Iceberg's optimistic concurrency control guarantees that one commit succeeds while the concurrent writer receives an update notification and automatically retries against the latest snapshot.
Why use Apache Iceberg over proprietary table storage?
Apache Iceberg eliminates storage vendor lock-in by decoupling data storage (Parquet files in S3/GCS/Azure) from compute engines. Multiple engines—Spark for heavy ETL, Trino for sub-second interactive analytics, BigQuery for enterprise BI, and DuckDB for fast local queries—can query the exact same data files without expensive ETL replication.
What is the performance overhead of querying Iceberg tables compared to native warehouse formats?
At scale, Iceberg query performance is comparable to native proprietary formats because Iceberg maintains hierarchical metadata (manifest lists and manifest files) containing column-level min/max metrics, enabling aggressive file pruning before any data files are fetched from object storage.
Source context: Original announcement / coverage