On this page
Why this happens
Two workers can read the same value and independently calculate a replacement. Without a conditional write, the last successful request wins. Shopify supports compare-and-set in metafieldsSet starting with API version 2024-07.
How to fix it
Read the owner ID, metafield value and compareDigest together. Include that digest in the mutation input. If creating a field only when absent, explicitly send null for compareDigest. Omitting the property instead opts out of that protection. On a conflict, inspect userErrors, fetch the current value and apply your business rule again with a bounded retry policy. For fields owned by a single authoritative system, consider eliminating competing writers altogether.
Practical example
Example: two workers append different identifiers to a JSON metafield. Each reads the same list and digest. The first succeeds; the second must re-read and merge its identifier into the updated list. A mutation can accept up to 25 metafields and is atomic, so a failed conditional write can prevent the rest of the batch from saving.
- Create a disposable product metafield
- read its digest twice
- write with the first digest
- attempt a different value using the stale digest
- inspect userErrors and verify the original successful write remains
- re-read and retry with a freshly computed value
- test explicit null against an existing field
- verify an unrelated field in a failing batch remains unchanged.

