Optimizing Pipeline Concurrency
This lesson explains concurrency limits, and how to balance performance with cost.
Learning outcomes
After completing this lesson, you will be able to:
- Explain parallel job limits.
- Decide how many parallel jobs to buy.
- Configure concurrency groups in GitHub Actions.
- Choose concurrency settings in Azure Pipelines.
Concurrency limits
In Azure Pipelines, concurrency is licensed through parallel jobs. One parallel job lets one job run at a time across the organization, so with three parallel jobs, a fourth job waits in the queue. Microsoft-hosted and self-hosted parallel jobs are counted separately. Jobs waiting for a check, or those in an agentless server job, do not consume a parallel job. New organizations have a maximum limit of 25 Microsoft-hosted parallel jobs, which support can raise.
In GitHub Actions, plans set limits on concurrent hosted jobs. Standard runners allow 20 on Free, 40 on Pro, 60 on Team and 500 on Enterprise, with lower macOS limits. Self-hosted capacity is limited by your runners.
What counts against concurrency
Deciding how many parallel jobs to buy
Queue time gives the answer. If jobs regularly wait while developers are working, then more parallel jobs would pay for themselves in saved time. If jobs rarely queue, more would be wasted. Azure DevOps shows queue and concurrency history under Organization settings > Parallel jobs > View in-progress jobs, and analytics adds a trend. A rough starting point is one parallel job for every four to five active users, adjusted with evidence.
Peaks matter. A team with a morning peak might accept brief queues rather than pay for capacity that sits idle all afternoon. Because capacity is shared across an organization, a long test matrix from one team can delay everyone else. maxParallel and max-parallel stop one pipeline from taking all available capacity.
Sizing parallel jobs
Controlling concurrency in GitHub Actions
The concurrency key creates a named group. Only one run or job in a group is active at a time, and one more can wait as pending. Any further pending run replaces the earlier pending one. With cancel-in-progress: true, a newer run cancels the one in progress.
name: pull-request-checks
on: pull_request
concurrency:
group: pr-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: npm testThe group name uses the pull request number, so each pull request has its own group. A new push cancels the outdated run for that pull request, and other pull requests are unaffected. This is a simple and effective saving.
Deployments need the opposite treatment. Cancelling a deployment halfway through can leave a system in a broken state, so a production group should not cancel what is in progress.
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
concurrency:
group: production-deploy
cancel-in-progress: false
steps:
- run: ./deploy.shThe following diagram shows the concurrency setting and the two runs.

Concurrency groups
Controlling concurrency in Azure Pipelines
Azure Pipelines has several settings, and each deals with a different problem.
batch: trueon a CI trigger combines commits that arrive during a run into one later run, instead of one run for each commit.- Pull request settings with
autoCancel: true, which is the default for theprtrigger, cancel a run when a pull request receives a newer commit. - Exclusive lock on an environment lets only one run deploy at a time, and
lockBehaviordecides between the latest run and a sequence. - Maximum parallel in a matrix limits how many of its jobs run at once.
The following table summarizes the settings.
| Goal | Azure Pipelines | GitHub Actions |
|---|---|---|
| Stop outdated pull request runs | autoCancel on pr | concurrency with cancel-in-progress: true |
| Merge rapid commits into one run | batch: true | concurrency keeps only the newest pending run |
| Serialize deployments | Exclusive lock | concurrency group with cancel-in-progress: false |
| Limit a matrix | maxParallel | max-parallel |
Concurrency settings on both platforms
Overlapping deployments
A GitHub Actions workflow deploys on each push to main. Two quick pushes caused two deployments to run together, leaving the environment in a mixed state. Older deployments should not be interrupted once started. What should you add?
Add a concurrency group to the deployment job, with cancel-in-progress: false. The second run then waits for the first to finish. Setting cancel-in-progress: true would interrupt a deployment already running, which conflicts with the requirement. max-parallel applies only within a matrix, and the two runs are separate.
Why include a pull request number in a concurrency group name?
Show answer
Each pull request then has its own group, so a new push cancels only that pull request's outdated run.
Exam Tips
Remember for the exam
- A parallel job lets one job run at a time across the organization.
- Queue time shows whether to buy more capacity.
- Use cancel-in-progress: true for pull request checks, never for production deployments.
- batch: true combines commits; Exclusive lock serializes deployments.
- A stage waiting on approval does not use a parallel job.