What You'll Learn
- 1Explain which parts of a Databricks workspace on GCP Databricks operates and which parts you pay for
- 2Model the Unity Catalog hierarchy and grant privileges at the narrowest object that works
- 3Tune Delta Lake files and clusters for a GCP workload instead of accepting the defaults
- 4Compare Databricks, Dataproc, and Dataflow for a given pipeline and justify the choice
Databricks on Google Cloud is a managed Spark platform whose control plane is operated by Databricks while the compute that runs your jobs sits on virtual machines in your own network. That split explains most of the cost, security, and operations questions that come up in design reviews, so this lesson starts there, then walks the governance model, the file layout that makes Spark perform, and the alternatives you would compare it against.
Where the workspace actually runs
The control plane holds workspace metadata, notebook definitions, job configurations, and the Unity Catalog metastore, and Databricks operates it. The data plane is where your code runs: worker and driver virtual machines inside your VPC, reading and writing buckets in your project, with traffic staying on Google's backbone between them. You pay twice, once in Databricks units for the compute the platform provisions and once in GCE for the machines themselves, which is why a forgotten always-on cluster shows up on the GCP invoice as well as the Databricks one.
Because data never leaves your project to be processed, the network story is simpler than it looks: you control the VPC, the bucket permissions, and the service accounts the data plane assumes. What you do not control is the control plane's metadata, so anything that must stay out of Databricks entirely, such as raw regulated payloads, belongs in your storage with access mediated by Unity Catalog rather than uploaded into notebooks.
One constraint is worth settling before anything is built. A workspace is created in a single region, and a Unity Catalog metastore is regional, so the region you pick governs where governance metadata lives for its lifetime. Organisations that scatter workspaces across regions end up maintaining the same grants twice and reconciling catalogs by hand, which is why most teams standardise on one region per data plane and let storage alone be multi regional.
The Unity Catalog hierarchy
Unity Catalog is the governance layer that replaced per-workspace permissions: one metastore per account and region, containing catalogs, schemas, tables, views, and columns, with grants applied at any level and inherited downwards. Storage is never implicit; a storage credential wraps a service account and an external location binds a path to it, so a table can only be read if the identity has rights on both the catalog entry and the bytes underneath.
spark.sql("CREATE CATALOG IF NOT EXISTS production")
spark.sql("CREATE SCHEMA IF NOT EXISTS production.analytics")
spark.sql("""
CREATE TABLE IF NOT EXISTS production.analytics.sales (
order_id STRING,
customer_id STRING,
amount DOUBLE,
order_date DATE
)
USING DELTA
LOCATION 'gs://lakehouse-raw/sales/'
""")
spark.sql("GRANT SELECT ON CATALOG production TO `[email protected]`")
spark.sql("GRANT MODIFY ON SCHEMA production.analytics TO `[email protected]`")
spark.sql("REVOKE SELECT ON TABLE production.analytics.sales FROM `[email protected]`")
Grant at the highest level that is defensible and audit from there: catalog level grants scale, column level grants answer specific compliance questions, and both appear in the audit log that regulators ask to see. Notebooks that bypass the catalog with a raw gs:// path defeat the whole model, so enforce external locations to close that door.
Delta Lake on your bucket
Delta Lake stores data as Parquet files plus a transaction log under _delta_log, which is what gives Spark tables on GCS atomic commits, schema evolution, and time travel without a proprietary format. Writers commit by atomically swapping the log pointer, readers pick a version and ignore files added after it, and that combination is what lets a streaming job and a batch backfill touch the same table without corrupting it.
spark.conf.set("spark.databricks.delta.optimizeWrite.enabled", "true")
spark.conf.set("spark.databricks.delta.autoCompact.enabled", "true")
spark.sql("""
OPTIMIZE production.analytics.sales
ZORDER BY (customer_id)
""")
spark.sql("DESCRIBE HISTORY production.analytics.sales")
spark.sql("SELECT * FROM production.analytics.sales VERSION AS OF 7")
spark.sql("VACUUM production.analytics.sales")
Small files are the performance enemy on object storage, since every file costs a task. Enable optimize write and auto compaction so the writer batches them, run OPTIMIZE on a schedule for tables that receive many small appends, and keep ZORDER on the columns that appear in filters so data skipping has something to work with. VACUUM deletes files no transaction can reference any more, keeping a seven day grace period by default; shorten it only when you are certain no reader is still on an old version.
Cluster policies and the cost levers
An all purpose cluster is shared by analysts and stays up between sessions; a job cluster is created for one job and destroyed when it finishes. Almost every cost surprise comes from the first kind, and almost every fix is a policy that constrains what users are allowed to start.
cluster_config = {
"spark_version": "13.3.x-scala2.12",
"node_type_id": "n2-standard-8",
"num_workers": 4,
"autoscale": {"min_workers": 2, "max_workers": 10},
"spark_conf": {
"spark.sql.adaptive.enabled": "true",
"spark.sql.adaptive.coalescePartitions.enabled": "true",
"spark.databricks.delta.optimizeWrite.enabled": "true",
"spark.databricks.delta.autoCompact.enabled": "true"
},
"cloud_attributes": {
"availability": "PREEMPTIBLE_GCP",
"zone_id": "us-central1-a"
},
"data_security_mode": "SINGLE_USER"
}
Adaptive query execution is worth leaving on, because it rewrites shuffle partitions after it sees the real data sizes instead of the estimate. Preemptible capacity cuts machine cost sharply and is safe for fault tolerant batch jobs that retry, but never for a long interactive session. Cluster policies should pin the Spark version, cap the node type, and forbid the accidental monthly bill, then let users pick within those rails.
Databricks, Dataproc, or Dataflow
All three run on Google infrastructure, and the honest answer is that they are optimised for different shapes of work.
| Databricks on GCP | Dataproc | Dataflow | |
|---|---|---|---|
| Engine | Managed Spark with Delta and notebooks | Managed Spark and Hadoop clusters | Managed Beam, batch and streaming |
| Governance | Unity Catalog across catalogs and schemas | Per project IAM, no built-in metastore | Job level IAM and templates |
| Batch cost | Databricks units plus GCE | GCE per second, cluster sized by you | Worker time, autoscaled per run |
| Streaming | Structured streaming | Structured streaming on a long cluster | Native triggers, watermarks, autoscaling |
| Best for | Teams standardising on Spark and Delta | Lift and shift of existing Hadoop jobs | Unified batch and streaming with strong SLAs |
Reach for Databricks when the team lives in notebooks, needs Delta and Unity Catalog, and wants SQL and ML in one workspace. Reach for Dataproc when you are porting Spark code and want the cheapest possible cluster with no platform opinion. Reach for Dataflow when a single graph must cover both a nightly backfill and a streaming path with managed windowing.
Connecting to BigQuery, GCS, and secrets
Most estates keep the warehouse in BigQuery and the lake in GCS, so the connector matters more than the migration story. Attach the Spark BigQuery connector, read a table as a dataframe, and write results back when BigQuery is where the dashboard looks, while keeping the raw history in Delta on GCS.
spark.read.format("bigquery") \
.option("table", "project:analytics.orders") \
.option("filter", "order_date >= '2025-01-01'") \
.load() \
.write.mode("append") \
.saveAsTable("production.analytics.orders_enriched")
Credentials belong in a secret scope rather than in a notebook, and on GCP you can back scopes with Google Secret Manager so the material never sits in workspace metadata. DBFS paths such as dbfs:/mnt/lake are mounts onto GCS buckets, which is convenient and easy to misconfigure; mount read only for anything downstream of production, and let Unity Catalog's external locations be the governed path for everything else.
Common Mistakes
Leaving an always-on all purpose cluster running between analyst sessions
Fix: Attach cluster policies that enforce job clusters for pipelines, cap node types, and set an idle timeout so shared clusters shut themselves down.
Reading a GCS path directly from a notebook to bypass a slow table
Fix: Register the path as an external location and grant through Unity Catalog, so the shortcut still lands in the audit log.
Running VACUUM aggressively on a table with long running readers
Fix: Keep the default seven day grace period, since a reader pinned to an older Delta version fails once its files are removed.
Best Practices
- Use job clusters for pipelines and reserve all purpose clusters for interactive exploration
- Enable optimize write and auto compaction on write heavy Delta tables, then schedule OPTIMIZE
- Keep secrets in a Secret Manager backed scope and service accounts in your own project
Key Takeaways
- The control plane is operated by Databricks while data plane machines run in your VPC and bill to your GCP project
- Unity Catalog grants inherit downward through catalog, schema, and table, and storage access needs a credential as well as a grant
- Delta on GCS gives ACID commits through an atomic log swap, with time travel reading a version instead of a snapshot copy
- Databricks costs Databricks units plus GCE, Dataproc costs only GCE, and Dataflow bills worker time per run
Interview Questions
Q1: What is Unity Catalog?
It is the unified governance layer for data and AI on Databricks: one metastore per account and region holding catalogs, schemas, tables, and columns, with inherited grants, external locations that bind paths to credentials, and a full audit trail of who read what.
Q2: How does Databricks on GCP differ from Dataproc?
Databricks is a platform: notebooks, Unity Catalog, Delta, and jobs with policies, paid as Databricks units plus the GCE machines underneath. Dataproc is Google's managed Spark with per second cluster billing and no opinionated metastore, which makes it cheaper and plainer for lifting existing Spark code across.
Q3: What does Delta Lake add over raw Parquet on GCS?
A transaction log next to the files, which gives atomic commits, schema evolution, time travel by version, and enforcement of constraints. Raw Parquet has none of that, so concurrent writers can interleave and a partial write is indistinguishable from a complete one.
Q4: How do you cut Spark cost without rewriting jobs?
Switch batch work to preemptible machines with retries, turn on adaptive query execution and coalesced partitions so shuffles match real data sizes, use job clusters instead of shared ones, and apply a policy that blocks oversized node types.
Q5: How do you integrate Databricks with BigQuery?
Use the Spark BigQuery connector to read warehouse tables as dataframes and write curated results back, keeping raw history in Delta on GCS. Credentials come from a secret scope, and the split lets SQL consumers stay in BigQuery while Spark handles the transformations.