Databricks reverse ETL
Import people, objects, and events from Databricks into Customer.io. You write SQL queries against a Databricks SQL warehouse; we run them on a schedule and send the results to your destinations.
This page covers importing data from Databricks into Customer.io. To send Customer.io data to Databricks, see Databricks data warehouse sync.
Best practices
Before you add a Reverse ETL source, you should take some measures to ensure the security of your customers’ data and limit performance impacts to your database and Customer.io workspace.
-
Create a new database user/service account. Implement a database user with minimal privileges specifically for Customer.io import/sync operations. This account only requires read permissions with access limited to the tables you want to sync from.
-
Avoid using your main database instance. Consider creating a read-only database instance with replication in place, lightening the load and preventing data loss on your main instance.
-
Sync only the data that you’ll use in Customer.io. Limiting your query can improve performance, and minimizes the potential to expose sensitive data. Select only the columns you care about, and make sure you use the
{{last_sync_time}}to limit your query to data that changed since the previous sync. -
Limit your sync frequency so you don’t sync more than necessary and consume unnecessary resources. If the previous reverse ETL operation is still in progress when the next interval occurs, we’ll skip the operation and catch up your data on the next interval. You should monitor your first few reverse ETL intervals to ensure that your sync doesn’t impact your system’s security and performance—frequently skipped operations may indicate that you’re syncing too often.
Set up your Databricks environment
As a part of setup, you'll need to provide OAuth client credentials (a client ID and client secret) for a Databricks service principal with read access to the data you want to sync.
To integrate with Customer.io, you’ll need to:
- Set up a service principal and grant it permissions to the data you want to sync. This is how Customer.io connects to your Databricks workspace.
- Allowlist Customer.io’s IP addresses if you use IP access lists.
- Set up a SQL warehouse for your syncs if you haven’t already.
Set up a service principal
Customer.io connects to Databricks as a service principal, a non-human identity with its own credentials and permissions (sometimes called a “service account”). You must be an admin in Databricks to create a service principal.
-
Create a service principal in your Databricks workspace and generate an OAuth secret for it. Save two values for the person setting up the integration in Customer.io:
- The service principal’s application ID (a UUID). This is the client ID.
- The OAuth secret. This is the client secret. Databricks shows it once, when you generate it.
-
Grant the service principal access to the data you want to sync. It needs three privileges:
USE CATALOGon the catalog andUSE SCHEMAon the schema so it can connect, andSELECTon each table you want to sync so that sync queries can read your data. You can grant these in Catalog Explorer or in a SQL editor.Catalog Explorer
You can work through these steps separately at the catalog, schema, and table levels. Or, you can grant access to the entire catalog, which should grant all the necessary privileges.
- In your Databricks workspace, go to Catalog.
- Select the catalog, schema, or table you want to grant access to.
- Go to the Permissions tab and click Grant.
- Search for your service principal by name.
- Select the privilege for the object you selected:
USE CATALOGfor a catalog,USE SCHEMAfor a schema, orSELECTfor a table. - Click OK.
To give the service principal read access to every table in a schema, grant
SELECTon the schema instead of on each table.SQL editor
Run these statements in a Databricks SQL editor. Replace the catalog, schema, and table names with your own, and
<application-id>with the service principal’s application ID:SQL-- connect-time access: lets the service principal see the catalog and schema GRANT USE CATALOG ON CATALOG my_catalog TO `<application-id>`; GRANT USE SCHEMA ON SCHEMA my_catalog.my_schema TO `<application-id>`; -- sync-time access: lets sync queries read the tables GRANT SELECT ON TABLE my_catalog.my_schema.my_table TO `<application-id>`;Grant
SELECTon each table you plan to sync. To grant read access to every table in the schema instead, runGRANT SELECT ON SCHEMA my_catalog.my_schema TO .... -
Grant the service principal access to your SQL warehouse. This is compute access, not a Unity Catalog privilege, so it isn’t a SQL
GRANT. In Databricks, go to SQL Warehouses, open your warehouse, click Permissions, and add the service principal with Can use.
Allowlist Customer.io’s IP addresses
If your workspace uses IP access lists, add our IP addresses to the allow list. Otherwise, Databricks rejects our connections before we can authenticate.
If you use a firewall or an allowlist, you must allow the following IP addresses so we can connect to your database. Make sure you use the correct IP addresses for your account region.
| US Region | EU Region |
|---|---|
| 34.29.50.4 | 34.22.168.136 |
| 35.222.130.209 | 34.78.194.61 |
| 34.122.196.49 | 104.155.37.221 |
| 34.9.152.53 | 34.78.153.242 |
| 34.170.216.131 | 34.78.94.137 |
| 35.222.84.131 | 34.140.151.135 |
| 34.57.129.127 | 34.62.147.132 |
Choosing a SQL warehouse
Every sync and every query preview runs on a Databricks SQL warehouse in your account. Databricks bills you for the compute, so there are a few things you’ll want to account for to keep your syncs reliable and costs predictable:
- Use a serverless warehouse whenever possible. Serverless warehouses start in seconds. Classic and pro warehouses take 2-5 minutes to start from a stopped state, which delays syncs and can cause “warehouse is starting” errors during setup.
- Set an auto-stop timeout. Each sync wakes the warehouse, and a running warehouse keeps billing until it stops. Set an auto-stop timeout so the warehouse shuts down between syncs. Serverless warehouses support short timeouts because restarts are fast.
- Size the warehouse for your queries. A larger warehouse runs each query faster but costs more per hour. If individual sync queries run slowly or time out, size up. Databricks’ sizing guidance can help you pick a starting size.
- Watch for queueing. A warehouse runs a limited number of queries at once and queues the rest. If you run many syncs on the same schedule, or share the warehouse with other consumers, you can experience queues that delay your syncs to Customer.io. Stagger your sync schedules, add capacity, or give Customer.io its own warehouse.
Set up your Databricks integration
Before you start, you’ll need a few things to set up the connection with Databricks:
- Your Databricks service principal’s client ID (application ID) and client secret.
- Your Databricks warehouse’s server hostname and HTTP path. In Databricks, go to SQL Warehouses, open your warehouse, and click Connection details to find these values.
- The catalog and schema that contain the data you want to sync.
Set up your Databricks connection
- Go to Integrations. In the Directory tab, pick the Databricks Data in integration.
- Fill in the connection form and click Connect.
- Name: a friendly name that helps you recognize your database whenever you reference it in Customer.io.
- Server hostname: the hostname of your Databricks warehouse without
https://—for example,dbc-a1b2c3d4-e5f6.cloud.databricks.com. The hostname format differs by cloud provider. Leave the Port at443unless Databricks tells you otherwise. - HTTP path: the HTTP path of your Databricks warehouse, like
/sql/1.0/warehouses/abc123def456. - Client ID: the service principal’s application ID.
- Client secret: the service principal’s client secret. We store this securely and never display it. You’ll need to re-enter it whenever you update the connection.
- Catalog and Schema: set where your sync queries look for a table when you don’t use its full name. To read other tables the service principal has access to, use their full names in your query, like
catalog.schema.table. Databricks reads a two-part name likeanalytics.ordersasschema.tablein your connection’s catalog (as opposed tocatalog.schema).
- Click Connect to make sure the connection works.
- When you’re done, click Next: Define Query to set up your first sync.
Set up a sync
Now you can set up a sync. A sync determines the type of data (identify, track, etc) you want to import from your database and how often it runs.
See Queries for each sync type for what each sync type expects and for examples written for your database. Click Run query to preview results and make sure that your query selects the right information. Click Enable Databricks to enable your sync.
After you set up your incoming integration, you can add additional syncs to import different types of data from your database. For example, you might want to import identify data for your users, and track data for their actions. Subsequent syncs can rely on your existing database, or you can add another database within your integration.
-
In your integration, go to the Syncs tab and click Add Sync.
-
Select your database or add a new one and click Next: Create Sync.
-
Set up a sync
A sync is the type of source data (
. You can set up syncs for each type of data you want to import.identify,track, etc) you want to import from your database. A sync is essentially the type of source call you want to make.
- Provide a Name and Description for the sync. This helps you understand the sync at a glance when you look at your integration’s Overview later.
- Select the type of data you want to import.
- Set the Sync Frequency, indicating how often you want to query your database for new data. You should set the frequency such that sync operations don’t overlap. Learn more about sync frequency.
- Select when you want to start the sync: whether you want to begin importing data immediately, or schedule the sync to start at a later date.
-
Enter the query that selects the data you want to import. See Queries for each sync type for what each sync type expects and for examples written for your database. Click Run query to preview results and make sure that your query selects the right information.
-
Click Enable sync to enable your sync.
Sync frequency
You can sync data as often as every minute. However, we recommend that you set your sync frequency such that sync operations don’t overlap. If you schedule syncs such that a sync operation is scheduled to start while the previous operation is still we’ll skip the next sync operation.
Each sync run wakes your SQL warehouse, so your sync frequency affects your Databricks bill. If you don’t need near-real-time data, a longer interval paired with an auto-stop timeout keeps the warehouse stopped most of the time.
Semantic events: Deleting people, groups, and more
You may notice that this integration doesn’t have sync types to delete people, groups, or other objects. To do these kinds of operations, you’ll use what we call semantic events. These are events with specific names that indicate a delete operation. When your Track sync picks up events with an event name we recognize, we’ll perform the associated action—like deleting a person or group.
For example, if you send an event with the name User Deleted, we’ll delete the person from your workspace. See Customer.io Semantic Events for more information.
The semantic events we support are:
| Event Name | Action |
|---|---|
Device Created or Updated | Add or update a mobile device. |
Device Deleted | Delete a mobile device. |
User Deleted | Delete a person. |
Object Deleted | Delete a custom object. |
Relationship Deleted | Delete a relationship. |
User Suppressed | Suppress a person. |
User Unsuppressed | Unsuppress a person. |
Report Delivery Event | Report in-app message events (like delivery, open, click) outside of our JavaScript integration. |
Troubleshooting
Your SQL warehouse is starting
If you test the connection or preview a query while your warehouse is stopped, the request fails with a message that your SQL warehouse is starting. Classic and pro warehouses take 2-5 minutes to start; wait for the warehouse to report Running in Databricks, then try again.
Scheduled syncs handle this on their own: when a sync hits a stopped warehouse, we retry for up to 5 minutes while it wakes. The sync starts late but succeeds. If the warehouse takes longer than 5 minutes to start, the run fails and we try again at the next scheduled interval.
To avoid cold starts entirely, use a serverless warehouse, which starts in seconds.
Authentication failures
If we can’t sign in to Databricks with the stored credentials, the source shows a banner explaining what went wrong. Common causes:
- The client secret expired or changed. Databricks OAuth secrets carry an expiration date from the moment you generate them, and rotating or deleting a secret invalidates the one we stored.
- The service principal no longer exists. Someone deactivated or deleted it in Databricks.
To fix it, generate a new OAuth secret for the service principal in Databricks, then open the source’s connection settings in Customer.io and re-enter the client ID and the new client secret. Saving the form with working credentials clears the error. Because we never display the stored secret, you re-enter it whenever you save the connection.
If authentication fails on a brand new connection, check the Server hostname: a hostname that points at the wrong workspace fails the sign-in even when the credentials are right.
Permission errors
If the connection test reports that the service principal can’t access your data, grant the Unity Catalog privileges: USE CATALOG on the catalog, USE SCHEMA on the schema, and SELECT on the tables you sync.
If the test reports that a catalog or schema is missing or not visible, check the names in Databricks Catalog Explorer. A catalog or schema the service principal has no privileges on reports as missing, so this error can also mean a missing USE CATALOG or USE SCHEMA grant.
A connection can also pass the test and then fail at sync time. The test checks catalog and schema access, but sync queries need SELECT on the tables they read.
Query errors in the preview
When a query fails in the Run query preview, Customer.io shows an error with a headline and hints to help you fix common errors. Expand Error details to see the full error message from Databricks.
| Error | What it means and how to fix it |
|---|---|
Databricks can’t find the table or view <name> | Databricks couldn’t find the table in the place it looked. For a one-part name like orders, Databricks looked in your connection’s default catalog and schema. For a two-part name like analytics., Databricks read the name as schema. in your connection’s default catalog. To read a table anywhere else, use its full name: catalog.. If you already used a full name, check the name and that the service principal has access to the table. |
Databricks can’t find the schema <name>Databricks can’t find the catalog <name> | Check the name, and check that the service principal has access to the schema or catalog. Databricks reports a schema or catalog that the service principal can’t access as missing. |
This workspace doesn’t allow hive_metastore names | Your Databricks workspace doesn’t allow queries against hive_metastore. Use a Unity Catalog name instead: catalog.. |
Databricks can’t find the column <name> | Check the column name, and check that the column is in the table you select from. When Databricks finds a similar column name, the hint suggests it. |
Syntax error near <token> | The hint gives the line and position where Databricks stopped reading your query. Databricks quotes names with backticks, not double quotes. If you write an alias like "traits., Databricks reads it as text and reports a syntax error. Write AS `traits. instead. |
| That query returned an error | Customer.io doesn’t have a hint for this error. The message from Databricks appears in the banner or under Error details. |
Slow syncs and timeouts
If syncs run slower than you expect, or individual queries time out:
- Check for queueing. Your warehouse runs a limited number of queries at once. Other workloads on the same warehouse, or many syncs on the same schedule, queue behind each other. Stagger your sync schedules or give Customer.io a dedicated warehouse.
- Size up the warehouse if a single query is slow on its own. Complex joins over large tables need more compute.
- Narrow the query. Use
last_sync_timeso each run reads only rows that changed since the previous sync instead of the whole table.
Query results are too large
A single sync run can return at most 20 GiB of results. If your query returns more than that, the run fails with a message telling you to add a filter or split the sync. To fix it, add a last_sync_time filter so each run reads only changed rows, or split the query into separate syncs that each cover part of the table.
Repeated failures pause a sync
If a sync keeps failing on an error that won’t resolve on its own, like a query with a syntax error or a table that no longer exists, we pause the sync. The pause prevents scheduled runs from waking your warehouse when those runs can’t succeed. Authentication failures don’t pause a sync. They show a banner instead.
You can resume the sync by fixing the issue and saving your changes.