My Cache Fix Fell Back to the Old Bug Whenever Shopify Said Throttled

2026-11-29来源 dev.toEnglish

In mid November I shipped a content hash that was supposed to stop one sale from refreshing a whole shop. For a few days it looked like the fix was holding.

From the 19th to the 21st the shop wrote between 19,805 and 44,323 ISR units a day. Vercel counts ISR writes in units, and larger changed output needs more units each time it is stored. Then Sunday, November 22, came in at 70,144 units with nothing deployed.

The shop is Lady Blue, the small headless Shopify store on Next.js 16 and Vercel Pro from my previous post. This follow-up is about the fallback I wrote into that fix.

How the hash decides what to refresh

For every product, the webhook handler keeps a sha256 of what the shop shows about it in a product metafield, with availability as a plain yes or no and the stock count left out. On products/update or a stock webhook the handler compares a fresh hash with the stored one. A match refreshes only that product's card, and a difference runs the old broad refresh.

When reading the stored hash fails, the handler runs the broad refresh anyway. Just in case.

Sunday's logs never loaded

The Vercel log view froze on a three-day range, so I never got Sunday's logs, and what caused Sunday is still unconfirmed. Monday afternoon is what I can show.

By about 16:30 on November 23 the day had already reached 68,395 write units. Between 13:00 and 17:30 the runtime logs showed 100 webhook events going through the hash logic, and 35 of them ended in a broad refresh. The handler logs a reason for each one:

  • 11 times the Admin GraphQL API answered "Throttled", the hash could not be read, and the fallback kicked in
  • 6 times a product got its first hash ever, because it had never had one
  • 12 times the hash really changed, mostly on stock, like a product flipping between available and sold out
  • 6 times the event came after our own background filler helper had written a metafield

The broad refresh exists for the 12 changed hashes. The stock sync cron ran at the time as well and found zero products to update.

Throttled took the most expensive path

Webhooks arrived in bursts. Between 17:08 and 17:10 there were many in a row, and at 17:08:59 one product refresh fell back to broad because the hash read was throttled. The hash read goes through the Admin GraphQL API, and 11 of those reads that afternoon hit its limit.

Shopify's rate limit docs describe a leaky bucket per app, and "if the bucket fills, you get a throttle error and have to wait for more bucket capacity to become available." The GraphQL APIs report this as a THROTTLED error inside a 200 OK response instead of sending a 429.

My handler treated that error like any other failed read. The broad refresh it fell back to is the one from the previous post, and it hits tags such as katalog and slowniki that sit on nearly every page of the shop. Observability for the last 12 hours on November 23 showed about 79,000 write units and about 4,400 tag revalidations.

One unrelated thing turned up in the same logs. A Storefront API query returned about 2.1 MB, which is over Vercel's 2 MB item limit for the data cache. The logs said "items over 2MB can not be cached" 44 times in 30 minutes, so that fetch skipped the data cache on every render.

What a throttle could trigger instead

The fallback could retry the hash read after a short wait, since the limits page says code "should stop making additional API requests until enough time has passed to retry" and puts the recommended backoff at one second. There is a ceiling on that. A webhook has to be answered within five seconds, so anything longer than a retry or two would sit better in a queue.

Another option is to keep serving the old card and leave the product to the next stock sync. The webhook best practices already say an app shouldn't rely on receiving data from Shopify webhooks and have a section on reconciliation jobs, and the shop has a cron for stock anyway. The cost is a card that may show the wrong availability until the cron runs, and the cron's own refresh invalidates the catalogue and dictionary tags as well.

Two other reasons on the list look easier to remove. Products without a stored hash could get one in a single pass, which would keep the first hash case out of real traffic. A metafield written by our own filler helper may not need a broad refresh at all.

Where the numbers stop

The biggest gap is Sunday. Without its logs I can't say how many of its 70,144 units came from the fallback.

Monday's numbers cover four and a half hours and 100 events, which is a small sample. In it the throttled reads account for 11 of the 35 broad refreshes.

Update, November 27: since the evening of November 26 a nightly job compares the stored hash for every product. On its first night it checked 397 products and found none that needed a broad refresh. In today's logs a throttled read shows up only in the background filler, which skips that product and moves on, and the six broad refreshes left came from products that sold out.

When your webhook handler can't tell whether anything changed, do you refresh everything or keep serving the old page until the next sync?

原文:https://www.a8q9.cn/en/article/my-cache-fix-fell-back-to-the-old-bug-whenever-shopify-said-throttled-e4778d.html

相关文章