Handling Shopify Function Metafield Size Limit

Since I am storing the required data in a metafield for use in the discount function, I discovered that metafields have a 10k character limit. Although JSON supports up to 2M characters, this restriction creates confusion on how to handle larger datasets. For a merchant, I cannot restrict creation beyond the required limit. So, what’s the best approach here? Should I create a new discount once the limit is reached (though there seems to be a limit of 25 discounts), or should I split the data across multiple metafields?

There is a related community discussion here.

Could you reduce the size by only writing JSON fields with values? Spliting the data across multiple metafields is viable but reducing the overall amount of data would be optimal.

Where should I include the discount value—such as percentage, fixed amount, or free gifts? Without this, I don’t see a way to provide a discount.

Could you provide more details about what isn’t working? I understand that you are writing a Discount Function that is reading metafields from the input and are running into the 10K character limit on each metafield. But it’s not clear to me how that problem relates to where you should store the discount value. I think that’s up to your app.

Issue Description:
In my app, users can configure discounts, and I store this data in a metafield with a 10,000-character limit. The discount setup includes product IDs and multiple deal bar configurations (for example, quantity breaks like “buy X, get Y% off”), stored as an array of objects.

Currently, everything works fine. However, if a user creates a discount setup that exceeds the 10k character limit, the metafield returns null. When this happens, all discounts stop working, not just the additional ones beyond the limit.

My Concern:
How can I handle this situation so that users don’t face issues when they exceed the character limit? Is my current approach correct, or should I consider a different way of storing and managing this data?

Knowing that your metafields are needed by a Function, and Functions have a 10K character limit per metafield, one option could be to have your app break the data into smaller chunks (<10K) and then create a metafield for each chunk.

Another technique that might help is for your app to reduce the size of the data in each metafield by only writing JSON fields with values.