Sub topic 3
Limiting Concurrent Runs
Assume you know Databricks notebooks, basic Python or SQL, clusters, and cron-style schedules. This chapter focuses on controlling production workflows rather than creating the first job.
Limiting concurrent runs
A job run is one execution of a job. Set max_concurrent_runs to prevent overlapping runs. A value of 1 makes a scheduled run wait while the previous run is still active. This protects shared tables and prevents duplicate processing.
{
"name": "daily-sales-pipeline",
"max_concurrent_runs": 1,
"email_notifications": {
"on_failure": ["[email protected]"]
},
"tasks": [
{
"task_key": "ingest",
"notebook_task": {
"notebook_path": "/Workspace/Shared/ingest"
}
},
{
"task_key": "publish",
"depends_on": [{"task_key": "ingest"}],
"notebook_task": {
"notebook_path": "/Workspace/Shared/publish"
}
}
]
}Notifying on failure
Configure notifications at the job or task level. Failure notifications can alert an email address, webhook, or other supported destination. Include enough context in the notification system to identify the job, run, and failed task.
Repairing a failed run
A repair run reruns failed or dependent tasks while keeping successful tasks from the original run. Use it after correcting the cause of failure, such as a missing input file or temporary service error. Check task dependencies before repairing. A downstream task may need to run again even if it did not itself fail.
Looping over inputs with For each tasks
A For each task runs the same inner task for multiple inputs, such as regions or table names. Limit its internal concurrency when the inputs could overload a service. Pass the current input as a task parameter.
Composing workflows with Run Job tasks
A Run Job task calls another job. Use it to separate reusable workflows, such as ingestion and reporting. The calling job can depend on the called job's completion, but permissions and parameter contracts must be clear.
Defining jobs as code
The Jobs API accepts JSON definitions. Databricks Asset Bundles define jobs in YAML so they can be reviewed, versioned, and deployed with the Databricks CLI. Keep schedules, task dependencies, and notification settings in source control. Store environment-specific values in bundle targets rather than copying job definitions manually.
Permissions and the run-as identity
The run-as identity is the user or service principal whose permissions a job uses during execution. Grant it only the required access to notebooks, catalogs, schemas, storage, and compute. A job can be editable by one team while running as a service principal, so review both ownership permissions and data permissions.
Exercise
A daily job sometimes overlaps and writes duplicate data. Which setting should you inspect first, and what value commonly prevents overlap?
Show answer
Inspect maxconcurrentruns. Set it to 1 when only one run should execute at a time.