- Mandatory configuration of IAM service accounts and GCS buckets to enable data flow.
- Using the BigQuery Storage API and predicate pushdown to optimize costs and performance.
- Implementing Lakehouse Federation using Unity Catalog for queries without data movement.
- Key differences between BigQuery's serverless slot architecture and Spark's cluster scaling.

If you're working in the data ecosystem, you know that connecting BigQuery with Databricks is one of those tasks that seems simple on paper, but has its challenges when you actually get down to it. Whether you want to migrate your workloads completely or you need both platforms to communicate to leverage the best of both worlds, the process requires fine-tuning permissions and a technical configuration that doesn't allow for mistakes.
The key here is understanding that we're not just talking about moving data, but about integrating a Google serverless architecture with the power of Databricks' Lakehouse . To prevent this from becoming a nightmare of authentication errors, a clear roadmap must be followed, covering everything from creating service accounts to managing external catalogs, ensuring a smooth and, above all, cost-efficient flow of information.
Setting up the environment in Google Cloud
To begin reading and writing data, the first step is to prepare the system in GCP. Enabling the BigQuery Storage API is crucial ; while it's usually enabled by default in new projects, in older ones you should check the console to confirm it's operational. Without it, data transfer performance will plummet.
The next step is to create an IAM service account dedicated exclusively to Databricks. This is where it's important to apply the principle of least privilege to avoid leaving the door open. If you only need to read data, the BigQuery Data Viewer and BigQuery Read Session User roles will suffice . However, if you need to write data, you'll have to add the BigQuery Data Editor and BigQuery Job User roles so that Databricks can execute the upload jobs.
One detail that's sometimes overlooked is the Cloud Storage bucket . Databricks needs temporary space in GCS to buffer the data before writing it to BigQuery. Once the bucket is created, you must assign the Storage Admin role to the service account you created earlier so it has free rein to move the temporary files.
Deployment and connection in Databricks
With GCP configured, we move on to the next step in Databricks. Ideally, you should create a workspace linked to your Google Cloud project and set up a cluster with runtime 7.6 or higher . In the cluster's advanced options, you'll need to enter the email address associated with your GCP service account to ensure automatic and secure authentication.
For those who prefer more granular control, JSON key-based authentication can be used . In this case, the key file must be Base64 encoded and added to the cluster's Spark configuration. It's a slightly more manual process, but very robust for environments where security is critical.
Strategies for querying and writing data
Once you have the bridge built, you have several ways to interact with the data. The most common is to use the BigQuery connector for Apache Spark , which allows you to read tables directly into a Python or Scala DataFrame. A huge advantage is predicate pushdown , which essentially makes the filters run on the BigQuery side, avoiding bringing millions of unnecessary rows into Databricks and saving time and money.
If you need to execute complex SQL, you can use the `query()` API . Unlike standard reads, this option delegates full execution to BigQuery and outputs the result to a temporary dataset. It's the winning choice when you want to optimize the size of the resulting dataset before it reaches the Spark cluster.
To write data, the process is reversed: you create a DataFrame in Databricks and save it using the bigquery format , specifying the temporary GCS bucket and the name of the destination table. You can choose overwrite mode to overwrite the existing table or append mode to add records.
Data Federation with Unity Catalog
If you use Azure Databricks or modern versions with Unity Catalog , you can implement Lakehouse Federation . This allows you to create a connection and a foreign catalog that mirrors your BigQuery database without physically moving the data. Essentially, it provides a direct window to Google Cloud from within the Databricks interface.
To make this fly, Databricks uses the BigQuery Storage API instead of JDBC, which significantly improves performance. This is where materialization comes in : some queries are read directly from storage, but external views or tables are materialized first to ensure all SQL functions are available. If you notice some queries are slow, you can force materialization using the `forceMaterialization` option.
Technical comparison and load migration
When deciding whether to migrate or integrate, it's important to understand that BigQuery is a serverless giant where Google manages resources (slots) for you, making it ideal for BI and ad-hoc analytics. Databricks, on the other hand, excels at massive data engineering and machine learning, allowing you to choose the instance type and scale clusters according to actual workload.
The biggest challenge of the migration is the SQL dialect . Although both follow the ANSI standard, there are differences in windowing functions and the syntax of certain aggregates. When moving code from Databricks SQL to BigQuery, you're very likely to encounter discrepancies in data types, such as the handling of BIGNUMERIC , which in Spark has a lower precision limit than in Google Cloud, requiring manual scaling.
Integrating these two tools allows you to leverage the flexibility of Delta Lake storage and the simplicity of BigQuery's on-demand queries. Ultimately, it's about choosing the right tool for the job: BigQuery for quick reports and Databricks for complex data pipelines and AI models.
FAQ
What permissions does the service account need to read BigQuery data from Databricks?
The service account must have the BigQuery Data Viewer and BigQuery Read Session User roles to access the tables and run read sessions.
What is the purpose of the Google Cloud Storage bucket in this connection?
It functions as a temporary storage area or buffer that Databricks uses to process data before permanently writing it to BigQuery tables.
What is the difference between a standard read and the query() API?
The standard read loads the data into a DataFrame, while the query() API executes the SQL directly in BigQuery and only transfers the materialized result.
What is Lakehouse Federation in the context of BigQuery?
It is a Unity Catalog feature that allows you to query BigQuery tables in real time without moving the data, creating a foreign catalog that mirrors the external source.
How does materialization affect performance and cost in BigQuery?
Materialization allows you to perform complex operations such as joins and aggregates in BigQuery before sending the data to Databricks, but it generates additional computational costs in GCP.
What data type issues can arise when migrating from Databricks to BigQuery?
The main conflict occurs with the BIGNUMERIC type, as BigQuery's precision exceeds Spark's, requiring adjustments to the scale to avoid truncation errors.
Is it possible to write data to BigQuery from a Databricks notebook?
Yes, by using the bigquery format in Spark's write method, provided that a temporary GCS bucket is specified and Data Editor permissions are available.


