Upstream jobs trigger on Databricks

The exact day when I published the blog post on the Table update trigger I discovered a different way for triggering Lakeflow Jobs having upstream dependencies not managed in the same Declarative Automation Bundle (DAB). Although this trigger is still in beta, it's a great addition to the scheduling capabilities.

4-day workshop · In-person or online

What would it take for you to trust your Databricks pipelines in production?

A 3-day bug hunt on a 3-person team costs up to €7,200 in lost engineering time. This workshop teaches you to prevent that — unit tests, data tests, and integration tests for PySpark and Databricks Lakeflow, including Spark Declarative Pipelines.

Unit, data & integration tests
Medallion architecture & Lakeflow SDP
Max 10 participants · production-ready templates
See the full curriculum → €7,000 flat fee · cohort of up to 10
Bartosz Konieczny
Bartosz
Konieczny

Why

If your Lakeflow job depends on a different job, you have different scheduling choices:

The schema below illustrates them:

Many choices but none of them come for free. Both data dependency and upstream pipeline modification require changing something that is not probably in your scope. You know it like me, asking for changes - even the tiniest ones - is not always prioritized compared to business use cases the upstream team is working on.

Fine, you might then opt for the second option where you define an approximate trigger time that would start your pipeline roughly after the upstream pipeline completes. You add some additional safety time before your pipeline triggers, and also create the task that is going to assert on the upstream pipeline completeness. It might work but not without a lot of implementation effort on your side. Besides, it can also bring some maintenance work as the upstream pipeline may complete longer than you have been expecting, and therefore, trigger alerts with your first completeness checking task.

None of them is perfect and for that exact reason Databricks Lakeflow runner proposes now a trigger called job completion.

Job completion trigger

Nothing better to start than the snapshot from the API documentation:

From that screenshot we can identify a few of the important features of this new trigger:

Once you define the trigger, you can get the jobs that triggered it from the {{job.trigger.job_completion.completed_jobs}} variable. It's an array where each entry contains: the job id, the run id, the workspace id, the termination status, and the completion time.

Consistency

There is a consistency trap, though. Let's consider your job depends on two upstream jobs that are managed by two different teams who have two different SLAs. One team has a strict SLA and in practice their pipelines are fixed within a few hours from any outage. Another team has much weaker SLA and their pipelines are usually not fixed for a few days.

If your job uses the ALL_SUCCESS condition and the weaker SLA job has not been running for several days, you will face one of these situations:

For that reason it's quite important to properly monitor your part and be alerted whenever data freshness of the table(s) managed by your job is broken. That way you can adapt and either prefer a temporary inconsistency, or prepare the cluster for handling a few days of data at once.

Demo

Ready to see some code? Let's check the trigger in action. The code is written against the Databricks Free Edition, so there are no cross-workspace access constraints.

Upstream jobs trigger is another great extension to the Lakeflow Jobs capabilities that favors the micro-DAB approach where teams can work independently on their bundles and despite the physical-repo isolation, be able to interact together.

Data Engineering Design Patterns

Looking for a book that defines and solves most common data engineering problems? I wrote one on that topic! You can read it online on the O'Reilly platform, or get a print copy on Amazon.

I also help solve your data engineering problems contact@waitingforcode.com đź“©