> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/controlling-deployments-with-barriers-resource-constraints-and-queue-steps.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Controlling resource usage with Barriers, Resource Constraints, and Queue steps

Compare Barriers, Resource Constraints, and Queue steps for controlling how deployments use resources

Harness has several ways to control deployments and resource usage and to protect resources and their capacity limits. Compare the differences, then use the practices below to choose one.

***

## What you will learn from this topic

* How to use a [Barrier](#barriers) to hold parallel stages or step groups until each one reaches the Barrier
* How to use [Resource Constraints](#resource-constraints) so two deployments do not use the same service and infrastructure at the same time
* How to use a [Queue step](#queue-steps) to queue pipeline executions that share a resource key
* How to [choose an option](#best-practices) for the deployment you need to coordinate

***

## Before you begin

Use the topic for the control you plan to add:

* **Barriers**: Go to [Synchronize parallel stages and step groups using Barriers](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/synchronize-deployments-using-barriers.md) to add a Barrier in one pipeline.
* **Resource Constraints**: Go to [Pipeline resource constraints](https://developer.harness.io/continuous-delivery/use-continuous-delivery/manage-deployments/deployment-resource-constraints.md) to review the default constraint on a service and infrastructure.
* **Queue steps**: Go to [Control resource usage with Queue steps](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/control-resource-usage-with-queue-steps.md) to add a Queue step and set its resource key.

***

## Control option definitions <a href="#control-option-definitions" id="control-option-definitions"></a>

The following options control how deployments use resources.

### Barriers <a href="#barriers" id="barriers"></a>

Barriers synchronize stages and [step groups](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/step-groups.md) of a pipeline that run in parallel. A Barrier holds one stage or step group until another stage or step group reaches a specific point.

For more information, go to [Synchronize parallel stages and step groups using Barriers](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/synchronize-deployments-using-barriers.md).

{% hint style="warning" %}
**Pipeline scope**

Barriers are scoped to the pipeline. You can use the same Barrier only within the same pipeline. If you add a **Barrier Name** from one pipeline into the Barrier step in another pipeline, it does not work.
{% endhint %}

### Resource constraints <a href="#resource-constraints" id="resource-constraints"></a>

Resource Constraints protect capacity limits by preventing simultaneous deployments to the same service + infrastructure combination. The service + infrastructure combination acts as a fixed key.

Resource Constraints are added to every stage by default. You can disable them in a stage's **Infrastructure** settings by enabling **Allow simultaneous deployments on the same infrastructure**.

For more information, go to [Pipeline resource constraints](https://developer.harness.io/continuous-delivery/use-continuous-delivery/manage-deployments/deployment-resource-constraints.md).

{% hint style="warning" %}
**Custom stages**

The automatic **Resource Constraints** setting does not apply to [Custom stages](https://developer.harness.io/harness-platform/use-harness-platform/pipelines/add-a-stage#add-a-custom-stage). **Resource Constraints** apply to a combination of service + infrastructure, and Custom stages have no services or infrastructures. You can use Barriers and Queue steps in any stage type.
{% endhint %}

### Queue steps <a href="#queue-steps" id="queue-steps"></a>

Queue steps synchronize pipeline executions. They queue pipelines that use a custom key.

Multiple deployments are queued so that one deployment completes before other deployments with the same key can proceed.

For more information, go to [Control resource usage with Queue steps](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/control-resource-usage-with-queue-steps.md).

{% hint style="warning" %}
**Account scope**

Queue steps are scoped to your entire Harness account.
{% endhint %}

If Queue steps with the same resource key exist in pipelines in projects A and B, and the pipeline in project A is running, the pipeline in project B is queued until the pipeline in project A is completed.

***

## Best practices <a href="#best-practices" id="best-practices"></a>

Use these practices to choose a resource control:

* **Barriers**: Use a Barrier when you want to coordinate the timing of different components' deployments with stages or step groups that run in parallel in the same pipeline. For example, the pipeline runs stages A and B in parallel, and a database migration in stage A must complete before a deployment in stage B. Place a Barrier step after the migration in stage A and before the deployment step in stage B.
* **Resource Constraints**: Use Resource Constraints when you want to prevent simultaneous deployments to the same service + infrastructure combination. This feature is enabled by default.
* **Queue steps**: Use Queue steps when you want to control the sequence of multiple pipeline executions. You can use Queue steps on different pipelines or on multiple executions of the same pipeline.

***

## Next steps

* [Synchronize parallel stages and step groups using Barriers](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/synchronize-deployments-using-barriers.md): Add a Barrier so parallel stages or step groups wait for each other.
* [Pipeline resource constraints](https://developer.harness.io/continuous-delivery/use-continuous-delivery/manage-deployments/deployment-resource-constraints.md): Review the constraint Harness adds for a service and infrastructure.
* [Control resource usage with Queue steps](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/flow-control/control-resource-usage-with-queue-steps.md): Queue executions that share a resource key.

{% @harness-feedback/feedback %}
