Sub topic 12
Limiting concurrent runs
This chapter assumes you can create a multi-task job, attach a Quartz cron schedule to it, and read the run history in the Jobs UI. Here you will learn how max_concurrent_runs decides what happens when a new run is due while an earlier run is still going.
Why concurrency needs a limit
A scheduled job starts on the clock, whether or not the previous run has finished. Suppose a job runs hourly and one run takes 90 minutes. At the next hour boundary, a second run is due while the first is still working. Two runs might then write to the same Delta table, overwrite each other's output, or fight over the same input files.
The job setting max_concurrent_runs caps how many runs of one job can be active at once. A run counts as active from the moment it starts until it ends.
How the setting behaves
The default is 1 for jobs created in the UI. For jobs created through the API, check the value you get back, because the API default can differ by version. Set it explicitly in code so the intent is visible.
When a new run is due and the limit has been reached, Databricks skips the new run. It does not queue the run by default. The skipped run appears in the history with a "Skipped" status, and the running one continues.
| Setting | Effect when a run is due and one is active |
|---|---|
| `max_concurrent_runs: 1` | The new run is skipped. |
| `max_concurrent_runs: 3` | The new run starts, up to three at once. |
The limit applies per job. It does not stop different jobs from running together, and it does not limit tasks inside one run. Tasks in a single run are governed by their dependencies.
{
"name": "daily-sales-pipeline",
"max_concurrent_runs": 1,
"schedule": {
"quartz_cron_expression": "0 0 6 * * ?",
"timezone_id": "UTC",
"pause_status": "UNPAUSED"
}
}The same field in a Databricks Asset Bundle looks like this:
resources:
jobs:
daily_sales:
name: daily-sales-pipeline
max_concurrent_runs: 1Choosing a value
Use 1 for most scheduled pipelines. This is the safe choice when runs read and write shared tables. Use a higher value when each run handles independent input, such as runs started by the API with different parameters. Each concurrent run uses its own compute, so a higher limit also raises cost and may hit cloud quotas.
Common errors
- Assuming skipped runs catch up. A skipped run is not retried later. If the job must process every interval, make the work incremental so the next run picks up what the skipped one missed.
- Fixing slow runs with concurrency. Raising the limit hides a run that is too slow for its schedule. Shorten the run or lengthen the interval first.
- Confusing the limit with retries. A retry reruns a failed task inside the same run. It does not create a new run, so it does not count against this limit.
Exercise
A job runs every 30 minutes with maxconcurrentruns set to 1. One run takes 50 minutes. What happens to the run due at the 30-minute mark, and is it run later?
Show answer
The run due at 30 minutes is skipped because the first run is still active and the limit is 1. It is shown as Skipped and is not run later. The next run starts at the 60-minute mark, after the first run has finished.