How revalidateTag Reached One of Three Next.js Pods and Kept a Recalled Product Page Live for 19 Hours
09:41 UTC. A Slack message from support, with a screenshot: a customer is on the product page for the Kestrel 2 space heater, "Add to cart" button live, and the email in the other window says that model was recalled yesterday.
the scramble
The recall notice came from the manufacturer at 14:05 the previous day. Merch unpublished the product in the CMS at 14:20.
The storefront is self-hosted Next.js 15 on Kubernetes, three replicas behind an ingress, with product pages using ISR
(revalidate: 86400) and on-demand revalidation. The CMS publishes a webhook to /api/revalidate.
So I check the obvious thing. The webhook log shows a 200 at 14:20:03 and the handler printed
revalidated tag product:kestrel-2. The CMS says unpublished. The page is still up.
First theory, from the support lead: browser cache. I curl the page with Cache-Control: no-cache and a cache-busting
query param. It comes back as a 404, correct. Then without the param:
Not a browser. Three out of six requests still get the live page, and which ones do looks random.
the hunt
Dead end one: the CDN. If the edge cached the 200, we would see the same answer from the same POP every time, and we did
not. The page also carries cache-control: s-maxage=86400, stale-while-revalidate from Next, but the CDN
config bypasses on x-nextjs-cache misses. I purge the CDN path anyway. No change in the 404/200 mix.
Dead end two: the revalidation itself failing. I call the endpoint by hand with the secret and the tag. 200 again, same log line.
Then I look at x-nextjs-cache on the responses:
The 200s are cache hits, served by the application, not the CDN. So some pods hold the old page and some do not. We
added an x-pod response header in the ingress config two weeks ago for another incident, and I can see
which pods answer:
Dead end three, short: a bad deploy on two pods. All three run the same image digest, started within 40 seconds of each other. Not that.
What is different is where the revalidation request went. I grep the ingress access log for the webhook:
one POST /api/revalidate at 14:20:03, upstream 10.4.2.31, which is m8zr6. Exactly one pod.
the find
Next.js, when self-hosted without a custom cache handler, stores its Incremental Static Regeneration output and the fetch cache on
the local filesystem of the process, under .next/server/app and .next/cache. That is the pod's own
container filesystem. Nothing shares it between replicas. revalidateTag marks entries stale in the cache of the
instance that executes the call. The webhook is one HTTP request, the ingress load-balances it to one pod, and that
pod invalidated its own copy. The other two never heard about it.
The 24 hour revalidate window made it worse. Each pod treated its stale copy as fresh until its own timer ran out, and the timers started whenever that pod last
regenerated the page. The earliest would not expire until mid-afternoon, so waiting it out was not an option.
It had probably been wrong for months. Every earlier on-demand revalidation fixed one pod and left the other two up to a day behind. Nobody noticed, because a copy edit showing up a few hours late looks like normal caching. A recalled product with a buy button does not look like normal caching.
the fix
Immediate, at 10:12: restart the two stale pods. A fresh container has an empty cache directory, so the first request to the product route renders against the CMS and gets the 404.
Permanent: Next supports a custom cache handler, configured in next.config.ts, that moves the ISR and tag state
out of the pod. We already run Redis, so the handler talks to it:
That is a sketch. A real one needs buffer serialization and a TTL on the keys, and I would start from a maintained package
such as @neshca/cache-handler before hand-rolling it. What matters is that the state now lives in one place, so one
webhook invalidates everything.
cacheMaxMemorySize: 0 matters. Without it each pod keeps an in-memory copy in front of Redis and the same bug
returns in a smaller form.
the aftermath
Impact: the recalled product page stayed purchasable from 14:20 on the 26th to 10:12 the next day on two of three pods, 19 hours and 52 minutes by our logs. Orders placed in that window: 14 for Kestrel 2. All were caught by the fulfillment hold and refunded the same morning, none shipped. Compliance wanted the exact window in writing, and the ingress log with the pod header let us give it.
- The cache handler shipped two days later. We confirmed it by revalidating a test tag and curling 30 times: 30 of 30 identical.
-
A synthetic check now runs after every
/api/revalidatecall: it fetches the path 12 times and alerts if the status codes differ. -
x-podstays on responses permanently. It turned a vague "sometimes stale" into a one-line grep. - Recalls and legal takedowns now also set a CMS-side kill flag the storefront reads on every request, because ISR is the wrong mechanism for anything that has to disappear at a specific minute.
A 200 from a revalidation endpoint tells you one process accepted the request, nothing more. With more than one replica I now check the outcome from outside, many times, and look at which instance answered.