Data lakehouse
Lay out a lakehouse on object storage with Apache Iceberg: bronze, silver and gold, a REST catalog, and time travel, as we run it in the lab.
A lakehouse is object storage plus a table format. The files are cheap and durable. Apache Iceberg adds what a folder of Parquet does not: a schema, a transaction around each write, and a history of snapshots so you can read the table as it was on a given morning. Spark and Trino both ask a catalog where the current snapshot is, and they get one answer. That shared answer is the whole design.
The pipeline overview compares a warehouse, a lake and a lakehouse. This lab is the layout we actually run: one bucket on OpenShift Data Foundation, three Iceberg namespaces, a REST catalog, and the SQL we use to look back at a snapshot. Ingestion lands files and change events. Spark writes the tables. This page is where those tables live.
Delta Lake and Apache Hudi solve the same problem. Iceberg is the format the engines in our lab share, so it is the one these jobs write.
Prerequisites
- OpenShift 4.x with
oc, and thedata-pipelinenamespace - Object storage. Ours is OpenShift Data Foundation (Ceph RGW) with the storage class
ocs-storagecluster-ceph-rgw. Another S3-compatible store works if you can create a bucket and a key - A REST catalog service,
iceberg-rest.data-pipeline.svc:8181. In our lab that process is Apache Polaris. Project Nessie is the one we stand up when a team wants a branch per experiment; the client settings in the Spark lab are the REST settings either way - The Spark image and service account from the Spark lab, for the SQL in this lab
- Trino, deployment
trino-coordinatorindata-pipeline, configured with the same catalog URI. Trino reads. Spark does the writes
oc get storageclass | grep rgw
oc get svc iceberg-rest -n data-pipeline
The bucket
Keep files that arrived as files outside the warehouse path. Iceberg owns everything under warehouse/ and will remove files when snapshots expire. A landing area it does not own is where you can still open the CSV a branch sent.
s3://lakehouse/
├── landing/ original files, by sender, not Iceberg
│ └── accounts/
│ ├── incoming/
│ └── accepted/dt=YYYY-MM-DD/
└── warehouse/ Iceberg warehouse root
├── bronze/
├── silver/
└── gold/
An ObjectBucketClaim asks the storage class for a bucket and writes the endpoint into a ConfigMap and the keys into a Secret of the same name. Jobs in the other labs mount that secret.
apiVersion: objectbucket.io/v1alpha1
kind: ObjectBucketClaim
metadata:
name: lakehouse
namespace: data-pipeline
spec:
generateBucketName: lakehouse
storageClassName: ocs-storagecluster-ceph-rgw
oc apply -f lakehouse-obc.yaml
oc get objectbucketclaim lakehouse -n data-pipeline
oc get cm lakehouse -n data-pipeline \
-o jsonpath='{.data.BUCKET_NAME}{"\n"}{.data.BUCKET_HOST}{"\n"}{.data.BUCKET_PORT}{"\n"}'
BUCKET_HOST and BUCKET_PORT are what Spark's fs.s3a.endpoint must use. The secret holds AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. If oc get storageclass shows a different RGW class name, use that name in the claim. The claim stays Pending until the class exists and the object store is healthy.
Bronze, silver, gold
The namespaces are the medallion layers. They are a promise about what happened to the data, not a brand of storage. All three are Iceberg tables in the same bucket.
| Layer | What a row is | What a job may do | Example |
|---|---|---|---|
| Bronze | What arrived, plus _ingested_at |
Append, or replace a day's raw partition. No business rules | bronze.transactions, one partition per load |
| Silver | A typed, de-duplicated entity | MERGE, mask a column, cast types, keep Unicode names as they were |
silver.accounts, silver.transactions |
| Gold | A grain a report or a model can use | Rebuild a partition from silver. Document the grain in the table name | gold.daily_balances, one row per account per day |
Bronze is the copy you can rebuild from. Silver is where a personal identifier is masked if the policy says analysts do not see it. Gold is what a dashboard and a feature pipeline are allowed to trust. A fix to a gold rule is a Spark job that rereads silver, or bronze if the mistake was earlier. It is not an edit in a SQL client against the live table, and it is not another extract from the core system.
Partition bronze and the large silver fact tables by day (days(booked_at) or the load date). A daily partition matches how we restate a day, and it matches the questions regulators ask. Do not partition by customer. That produces a pile of tiny files and a planning delay on every query. Gold balance tables can be partitioned by month if the readers always take a month at a time.
Bangla text is an ordinary string column. holder_name in silver is the name as it arrived, UTF-8, including নাম values. Do not add a transliteration column unless a named consumer has asked for one.
Create the tables
Run this SQL in a Spark session that already has the catalog settings from the Spark lab (spark.sql.defaultCatalog=lake, the REST URI, the warehouse path). The session time zone is Asia/Dhaka, so "the 1st of October" means that civil date in Dhaka.
SET spark.sql.session.timeZone=Asia/Dhaka;
CREATE NAMESPACE IF NOT EXISTS bronze;
CREATE NAMESPACE IF NOT EXISTS silver;
CREATE NAMESPACE IF NOT EXISTS gold;
CREATE TABLE IF NOT EXISTS bronze.transactions (
id bigint,
account_no string,
amount decimal(18, 2),
booked_at timestamp,
_ingested_at timestamp
) USING iceberg
PARTITIONED BY (days(booked_at))
TBLPROPERTIES (
'format-version' = '2',
'write.parquet.compression-codec' = 'zstd'
);
Format version 2 is what Spark and Trino in the lab both read and write. Stay on it until you have tried a newer version in both engines on a copy of the table. zstd is the compression we set on new tables. Adding a column later does not rewrite the old files:
ALTER TABLE silver.accounts ADD COLUMN branch_code string;
Readers that do not know branch_code still see the old columns. That is the schema change we want. A rename or a type change that is not assignment-compatible is a new column and a job, not an in-place alter you hope will fit.
Trino sees the same namespaces because it uses the same catalog. From the coordinator:
oc exec -n data-pipeline deploy/trino-coordinator -- \
trino --execute "SHOW SCHEMAS FROM lake"
oc exec -n data-pipeline deploy/trino-coordinator -- \
trino --execute "SHOW TABLES FROM lake.gold"
Trino's time-travel syntax is FOR VERSION AS OF and FOR TIMESTAMP AS OF. Spark's is VERSION AS OF and TIMESTAMP AS OF, which is what the next section uses. The snapshot ids are the same.
The catalog
Without a catalog, each engine has a favourite folder and a private idea of which file is current. Two writers then corrupt a table that both believed they owned. The REST catalog is the registry: a writer commits a new snapshot in one request, and every reader that asks afterwards receives that snapshot.
Spark has spark.sql.catalog.lake.uri pointed at http://iceberg-rest.data-pipeline.svc:8181. Trino's Iceberg catalog has the same URI. If Polaris is configured with a client id and secret, both engines read them from a Kubernetes secret (spark.sql.catalog.lake.credential on Spark). The value does not belong in Git.
SHOW NAMESPACES IN lake;
SHOW TABLES IN lake.silver;
A table that shows up in Spark and not in Trino is almost always a second warehouse path or a second catalog URI. Compare the two configurations before you rewrite anything.
Time travel
Every successful write is a snapshot. The history is on the table, and it is the first place to look when yesterday's report does not match this morning's.
SELECT committed_at, snapshot_id, operation
FROM lake.gold.daily_balances.snapshots
ORDER BY committed_at DESC;
Read that snapshot back without moving the table. Copy snapshot_id from the query above.
SELECT * FROM lake.gold.daily_balances VERSION AS OF <snapshot_id>;
SELECT * FROM lake.gold.daily_balances TIMESTAMP AS OF '2026-10-01 00:00:00';
The timestamp uses the session zone set earlier, so midnight is midnight in Dhaka. This is how you answer "what did we publish on the 1st?" while the current snapshot already contains a correction. It is also how you diff a bad load against the one before it.
Rolling back moves the current snapshot. Do it when a write was wrong and consumers must stop seeing it. It does not delete the later snapshot's files until an expire runs.
CALL lake.system.rollback_to_snapshot(
table => 'gold.daily_balances',
snapshot_id => <snapshot_id>
);
Expiring snapshots drops history you can no longer travel to, and then deletes the files no remaining snapshot needs. Keep more history than the oldest restatement you are still asked for. A year of regulatory look-back means a year of snapshots, or a deliberate export of the published figures, before you expire.
CALL lake.system.expire_snapshots(
table => 'gold.daily_balances',
older_than => TIMESTAMP '2025-10-01 00:00:00',
retain_last => 10
);
retain_last => 10 keeps the ten newest snapshots even if they are older than the cutoff. Run expire on a calendar you have written down, from the orchestration lab, not as a command someone pastes on a Friday.
Small files
CDC windows and hourly jobs write many small Parquet files. Planning a query then spends its time opening files. Look before you compact:
SELECT file_size_in_bytes, record_count, file_path
FROM lake.silver.transactions.files
LIMIT 20;
When that list is a long tail of tiny files, compact. The procedure rewrites data files into fewer of them and commits one new snapshot. Readers on the previous snapshot are unaffected.
CALL lake.system.rewrite_data_files(table => 'silver.transactions');
We compact silver after the daily merge, as an Argo workflow that depends on the merge succeeding. Bronze is compacted less often; it is an archive of loads, and a day's partition is usually one or two files already. Gold is compacted when a rebuild has sprinkled small files across many months.
rewrite_data_files is a Spark job like any other. Size the executors the way the Spark lab sizes them, and do not run it on the Trino coordinator.
What we refuse to do
- No second copy of gold in a private bucket. If a team needs a different grain, it is another gold table in this catalog, with an owner.
- No writes from a notebook against production namespaces. Notebooks read. The scheduled job writes. A notebook that must fix a table writes a new snapshot through the same Spark image, in a workflow you can find the next day.
- No expiration of bronze on a short timer. Silver and gold can be rebuilt from bronze. Bronze can only be rebuilt from the source, and the source has moved on.
- No catalog database on a laptop. The REST service runs on the cluster, next to the bucket, and both are backed up with the rest of the platform.
What's next
- Ingestion: how files reach
landing/and how change events reach Kafka before they are appended to bronze. - Apache Spark: the jobs that merge into silver and rebuild gold.
- Orchestration: the schedule for those jobs, and for
rewrite_data_filesandexpire_snapshots. - Data quality and governance: checks, a catalog people can search, lineage and masking on top of these tables.
- Pipelines for AI: document, feature and training-data flows that read the same gold tables.
The pipeline overview places this layout next to Kafka, Trino and the serving databases. Those serving databases are fed from gold. They are not where the history lives.