# Concurrency
This page explains how to limit the number of concurrent PipelineRuns for a Repository CR and how to integrate with Kueue for Kubernetes-native job queueing. Use concurrency limits when you need to control resource consumption or prevent PipelineRuns from overwhelming your cluster.

Set the `concurrency_limit` field to define the maximum number of PipelineRuns running at any time for a Repository CR. This prevents resource exhaustion and ensures predictable scheduling when multiple events arrive in rapid succession.

```yaml
spec:
  concurrency_limit: <number>
```

When multiple PipelineRuns match the event, Pipelines-as-Code starts them in alphabetical order by PipelineRun name.

Example:

If you have three PipelineRuns in your `.tekton/` directory and you create a pull
request with a `concurrency_limit` of 1 in the repository configuration,
Pipelines-as-Code executes all PipelineRuns in alphabetical order, one after the
other. At any given time, only one PipelineRun is in the running state,
while the rest are queued.

```mermaid
flowchart LR
%% title: Three PipelineRuns sharing a concurrency limit
  Ev@{ img: "/icons/pull-request.svg", label: "Pull request", w: 48, h: 48, constraint: "on" }
  Queue@{ img: "/icons/queue.svg", label: "Queue", w: 48, h: 48, constraint: "on" }
  A@{ img: "/icons/build.svg", label: "build", w: 48, h: 48, constraint: "on" }
  B@{ img: "/icons/test.svg", label: "lint", w: 48, h: 48, constraint: "on" }
  C@{ img: "/icons/test.svg", label: "unit", w: 48, h: 48, constraint: "on" }
  Done@{ img: "/icons/success.svg", label: "Finished", w: 48, h: 48, constraint: "on" }
  Ev -->|3 runs| Queue
  Queue --> A
  Queue --> B
  Queue --> C
  A --> Done
  B --> Done
  C --> Done

%% play: Limit of 1
%% Ev -> Queue : 3 runs | The three PipelineRuns are queued in alphabetical order
%% Queue -> A : start
%% A -> Done | Only when build finishes does the next one start
%% Queue -> B : start
%% B -> Done
%% Queue -> C : start
%% C -> Done
%% play: Limit of 2
%% Ev -> Queue : 3 runs
%% Queue -> A, B | Two PipelineRuns run side by side
%% wait 1000 | unit waits for a free slot
%% A -> Done
%% Queue -> C : start
%% B, C -> Done
```

For additional concurrency strategies and global configuration options, see [Advanced Concurrency](/docs/advanced/concurrency.md).

## Kueue - Kubernetes-native Job Queueing

If you need more sophisticated queue management than `concurrency_limit` provides, Pipelines-as-Code supports [Kueue](https://kueue.sigs.k8s.io/) as an alternative, Kubernetes-native solution for queuing PipelineRuns.
To get started, deploy the experimental integration provided by the [tektoncd/tekton-kueue](https://github.com/tektoncd/tekton-kueue) project. This allows you to schedule PipelineRuns through Kueue's queuing mechanism.

> [!NOTE]
>
> 
> The [tektoncd/tekton-kueue](https://github.com/tektoncd/tekton-kueue) project and the Pipelines-as-Code integration is only intended for testing.
> It is only meant for experimentation and should not be used in production environments.
> 



