Lesson 3 of 5 Maintaining Pipelines

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.

True or false

What counts against concurrency

Exam skills 3.6.3

Check which work consumes a parallel job.

Log in to try this activity Interactive activities are free with an account.

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.

Scenario questions

Sizing parallel jobs

Exam skills 3.6.3

Decide how much concurrency an organization needs.

Log in to try this activity Interactive activities are free with an account.

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 test

The 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.sh

The following diagram shows the concurrency setting and the two runs.

A concurrency group with cancel-in-progress: false on the deployment job. Two quick pushes to main no longer deploy together: the second run waits until the first finishes, and a deployment already running is never interrupted.
The group name is an example.
Scenario questions

Concurrency groups

Exam skills 3.6.3

Predict how GitHub Actions concurrency groups behave.

Log in to try this activity Interactive activities are free with an account.

Controlling concurrency in Azure Pipelines

Azure Pipelines has several settings, and each deals with a different problem.

  • batch: true on 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 the pr trigger, 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 lockBehavior decides 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.

GoalAzure PipelinesGitHub Actions
Stop outdated pull request runsautoCancel on prconcurrency with cancel-in-progress: true
Merge rapid commits into one runbatch: trueconcurrency keeps only the newest pending run
Serialize deploymentsExclusive lockconcurrency group with cancel-in-progress: false
Limit a matrixmaxParallelmax-parallel
Match the pairs

Concurrency settings on both platforms

Exam skills 3.6.3

Match each Azure Pipelines concurrency setting with its GitHub Actions counterpart.

Log in to try this activity Interactive activities are free with an account.
Worked example

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.

Check yourself

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.