Optimizing your workflows

When you build a workflow, you want to make sure it runs as efficiently as possible. This document outlines scenarios that might cause your workflows to be throttled or exhaust API limits and tips on how to resolve or workaround those issues.

Common performance issues

The section outlines common scenarios that can cause performance issues in your workflows. It is possible to have more than one scenario at the same time, which would increase the likelihood that you observe performance issues. For errors related to editor configuration or rate limiting, use the troubleshooting guide.

High volume triggers

High volume triggers are those where the underlying event happens frequently. For example, the trigger Product variant inventory quantity changed runs for every inventory change in a shop. The volume of a trigger is like a multiplier on any problem in your workflow. For example, if a workflow fetches 100 products, and it runs 1000 times per minute, then it will be fetching 100,000 products per minute. This can cause performance issues.

Solution: Optimize your workflows by using less data, or use waits steps to partition your workflow as outlined below.

Many workflows using the same trigger

In Flow, you can build more than one workflow using the same trigger. These workflows will run in parallel with one another when the event happens. This can be problematic if you run too many workflows using the same trigger for the following reasons:

  • The workflows can conflict with one another.
  • The workflows are trying to fetch data and call APIs at the same time, and your shop is limited in how many requests it can handle at once by Shopify API limits.

Solution: Combine workflows that use the same trigger into a single workflow. This also allows you to control when each of them executes, so that they don't conflict with one another. Combining workflows is especially useful if the workflows don't retrieve a lot of data or the data they retrieve is the same. If the workflows retrieve a lot of distinct data, you may find that keeping them separate results in better performance.

Using lists or the wrong data

When you build a workflow, you might use a list of objects, such as products or orders. If you use a list of objects, then Flow will fetch all of the objects in the list. This can be a problem when the list contains a lot of data.

Another common issue is accidentally selecting the wrong data. For example, to check product data on an order, you might have selected order / publication / products / tags instead of order / line items / product / tags. The first result is usually incorrect, as it fetches all the products for a publication when the intention is to check products on the order. Choosing such a large list can cause performance issues and choosing the wrong list can result in your automation doing the wrong thing.

Solution: Carefully select the data you need and avoid using lists when you don't need to. Test your workflows to ensure they are doing what you expect.

Metafields

Fetching individual metafield or metaobject data shouldn't cause performance issues. However, a common issue is choosing the list metafields and looping over all of the metafields on a resource. If a value field contains a lot of data, for example, when HTML objects are used, then this can result in a lot of data being processed and potentially causing performance issues.

Solution: Use the metafield object (docs) instead of metafields.

Overuse of Get data actions

Workflows using a Get data action such as Get order data are designed to return a maximum of 100 objects per workflow from Get data actions. Going over 100 objects can cause performance issues.

Solution: Run the workflow more often so that your query doesn't need to return more than 100 results. Reuse the same Get data action over making repeated queries.

No query filters in Get data actions

Get data actions call the Shopify API. If no query is present, then the API will either return all resources or none. This can cause performance issues, but it can also cause the wrong actions to be taken in your shop, if you use the data returned later in the workflow.

Solution: Always include query filters in your Get data actions.

Incorrect query filters in Get data actions

Get data queries support a limited set of query filters, a specific syntax, and a specific set of values that can be used in filters. Entering the wrong filter, filter value, or syntax can cause the entire query to be ignored, which can cause issues similar to when no query filter is present.

Solution: Use the documentation provided by the action in Flow to find the list of available query filters. Always test your query filters to ensure they return the expected data. You can use a Log Output action in Flow (to see the data returned), or you can call the Shopify Admin API directly (through an API client like Postman or through the app GraphiQL).

Additional solutions for common performance issues

Use Wait steps to delay data fetching

Wait steps allow you to pause a workflow for a specified amount of time, but wait steps can also be used to optimize your workflows. Each wait step effectively splits the execution of your workflow into separate blocks. When the workflow runs, it automatically fetches data that's required up until the first wait step (and fetches data again after the wait step for the rest of the workflow). If a workflow uses a high volume trigger and fetches a lot of data, but will take action only occasionally, then you can put any complex data or logic after a condition and wait step pair. For example:

  1. Trigger: Product variant inventory quantity changed
  2. Condition: Check if the product is in a collection
  3. If true, Action: Wait 2 seconds
  4. Action: Send an email to the customer (with lots of data)

In this example, the data required for step 4 is only queried after the Wait step completes. If the condition is usually false, this means the workflow will run faster and more efficiently.

What not to optimize

Using the same data in multiple actions

When you use the same field in multiple steps, Flow analyzes the usage of those fields and only fetches that data once. This means you can use the data as many times as you want without worrying about performance.

Can’t find the answers you’re looking for? We’re here to help.