Avoid Infinite Loops

If your workflow triggers an infinite loop, it could flood your message queue, slow down workflow processing, or worse, result in large overage charges.

Workflows with an Update trigger can be at risk of causing an infinite loop in a couple different situations:

Bi-directional sync

Consider a scenario to copy orders and keep inventory levels in sync with two workflows:

  • When a Shopify order is created, create an order in Salesforce

  • When a Salesforce order is created, create an order in Shopify

When a Shopify order is placed, the first workflow will run which will create a Salesforce order. This will trigger the second workflow, which will in turn trigger the first workflow. Now you have a never-ending loop of new orders.

Workflows affecting the same object

Consider this workflow that begins with a Product updated step and contains an Update product step:

When a Shopify product is updated, this workflow will be triggered and the same product will be updated. This will in turn trigger the workflow again, which could cause he product to be updated, and so on. MESA has special handling for duplicate messages which works in most cases, but not all, depending on the updates you are making.

Suggested structure

To avoid infinite loops, we always recommend adding a unique identifier to the object that was updated and then filtering by that identifier in the second step of your workflow. In the above example, you would add a Shopify add tag step to the end of the workflow that adds a "processed" tag:

And then confirm that the product does not contain that tag in the second step of the workflow:

The remedy for a bi-directional sync would be similar, but you would want to check that the tag does not exist in both workflows.

This would result in your automation running twice every time the product is updated (once to make the update, and a second time to hit the filter), which should be accounted for when selecting a plan.

Suggested structure using Include Fields

If you're updating an object and don't need to read it, you can use the Include Fields feature in reverse to avoid infinite loops. For example, if you're updating tags but don't need to read them in the workflow, use the Include Fields feature to include all the fields you're reading and exclude those you're not using, like tags. Doing so prevents the workflow from getting triggered when the only change is a tag modification.

In the example below, we have set a value for Include Fields. The workflow will only be triggered when the title, body, or variants are updated. Because tags are not included in the Include Fields value, updates to the product tags will not trigger the workflow. This structure prevents the workflow from being executed twice.

If you're using this structure, we strongly suggest reading the Include Fields documentation before making any changes to your workflow.

Last updated