Article

Incident review: a cache purge, memory growth and Redis timeouts

A blameless review of a latency incident after a cache purge: the signals to correlate, the fixes, and safer ways to purge and size a cache.

Published Updated 9 min read

A cache purge looks like a safe action: you remove old content, and the next request fetches the new version. For a server-rendered storefront, a full purge can also send a burst of uncached traffic to your app at the same moment. This post is a blameless review of a latency incident that followed a cache purge, and a guide to the general lesson: how the failure develops, which signals to correlate, how to mitigate, and how to purge and size your caches with less risk. It is written for engineers who run a server-rendered app, such as Next.js, behind a CDN and with a shared Redis cache. The Next.js examples use Next.js 16.4.6, the current version on 1 December 2026.

What happens after a full purge

Before a purge, the CDN and the app cache serve most page requests. Only a small share reaches your app. A full purge removes all of that at once, and the following chain can start:

  1. Every request is a miss. In Fastly, a purge all is always a hard purge. The next request for each object goes to origin. Fastly warns that a purge all can increase the load time of your site while the cache rebuilds.
  2. Every miss is a render. For each miss, the app fetches data from upstream APIs and renders the page. With ISR, Next.js then stores the result in its cache. With a shared cache handler on Redis, that store is a write to Redis.
  3. Containers do more work at the same time. Many renders run in parallel, so each container can hold much more work in memory than in normal traffic.
  4. Redis gets busy. All containers read from and write to Redis at the same time. Redis serves commands one after another on a mostly single thread, so a slow command makes every other client wait.
  5. Timeouts add load. Client timeouts start to fire. If your cache handler treats a timeout as a miss, a timed-out read becomes one more render, which adds more load.

Request collapsing in the CDN helps, but only partly. Fastly combines many requests for the same object into one origin request, so one popular page does not flood your origin. It does not help when thousands of different URLs miss at the same time. Also, collapsing only works well for cacheable responses. When a response is not cacheable, Fastly sends the queued requests to origin one after another, which can cause very long response times.

The app cache has its own risk. When you run several containers, the default Next.js cache is local to each instance. Next.js advises a shared custom cache handler, for example on Redis, so that all instances use the same cache. That makes Redis a critical part of every page render.

Correlate the right signals

No single graph shows this incident. You see it when you put the signals on one time axis.

Signal Where to find it What to look for
CDN cache hit ratio Fastly integration: fastly.hit_ratio, fastly.hits, fastly.miss A drop at the time of the purge
Origin requests Fastly integration: fastly.origin_fetches More requests that reach your app
App cache status The x-nextjs-cache response header: HIT, STALE, MISS or REVALIDATED More MISS responses, which means more renders
Container memory The container metrics of your platform A climb after the purge, towards the limit
Redis memory and evictions Redis integration: redis.mem.used, redis.mem.maxmemory, redis.keys.evicted Memory close to the limit, or evictions that start
Redis clients and latency redis.net.clients, redis.net.rejected, redis.info.latency_ms More connections, rejected connections, slower responses
Redis errors in the app Timeout errors in logs and Redis spans in traces Timeouts that start after the memory climb
App latency APM latency of the page routes A rise that follows the signals above

The metric redis.info.latency_ms is the latency of the INFO command that the Datadog Agent runs. It is a simple indicator of how fast Redis responds. On the Redis server, use the slow log to find slow commands, and the latency monitor to see latency events and their causes. Do not run KEYS in production. Use SCAN instead.

If you do not have APM on your Next.js app yet, see our post on Datadog RUM and APM for the Next.js App Router.

Then make every purge visible. Send a change event to Datadog each time a person or a pipeline purges a cache. The Datadog Events API accepts events in the category change, and Change Tracking shows them on dashboards, service pages and monitor status pages. With a purge marker on the latency graph, the next on-call engineer sees the link at once.

Mitigate during the incident

  1. Confirm the timeline. Line up the purge time, the drop in hit ratio, the memory climb, the Redis timeouts and the latency.
  2. Do not purge again. Fastly warns against a purge all when you see 503 errors, because a purge all overrides stale-if-error and sends even more requests to origin.
  3. Give the app room. Raise the container memory or the number of instances, so that the app can absorb the burst until the cache is warm again.
  4. Check Redis. Compare redis.mem.used with redis.mem.maxmemory, and check the eviction policy. With noeviction, Redis returns errors on commands that add data when it reaches the limit. Commands that only read still work.
  5. Watch the recovery. The incident is over when the hit ratio is back up, memory is flat, and Redis latency and app latency are back at their baseline.

Purge with less risk

A full purge is the bluntest tool you have. Use a smaller one where you can.

Approach What it does When to use it
Targeted purge Purges one URL or one surrogate key, so only the affected objects go A content change on known pages
Soft purge Marks objects as stale instead of removing them. The next user gets the stale object while the CDN fetches a new one Most content updates
Purge in batches Purges groups of surrogate keys with a pause between the groups Large catalogue or template changes
Time-based expiry Pages expire after a fixed lifetime, so you need no purge Pages that can be a few minutes old
Stale-while-revalidate The cache serves a stale page while it fetches a new one in the background Together with all of the above

In Fastly, you tag each response with the Surrogate-Key header and purge by key. Keys are case sensitive. A soft purge needs the header Fastly-Soft-Purge: 1 and works for URL and surrogate key purges, but not for a purge all. For a soft purge of everything, tag every object with a constant key, such as all, and soft purge that key. One batch request can purge up to 256 keys:

POST /service/<service-id>/purge HTTP/1.1
Host: api.fastly.com
Fastly-Soft-Purge: 1
Surrogate-Key: <key-1> <key-2> <key-3>

Authenticate the request with your API token, as the Fastly API reference describes. Send the next batch only when the origin metrics are back to normal.

A soft purge only helps when the CDN may serve stale content, and Fastly does not do this by default. Allow it in the response headers:

Cache-Control: max-age=600, stale-while-revalidate=30, stale-if-error=86400

With this header, the page stays fresh in the cache for 10 minutes. After that, a cache can serve the stale page for up to 30 seconds while it fetches a new one. With stale-if-error, a cache can serve the stale page for up to one day when the origin returns a 500, 502, 503 or 504 status. Stale content is only available for cacheable objects.

In Next.js, time-based ISR replaces many purges. Set a revalidation time on the page:

// app/[...slug]/page.tsx
export const revalidate = 300

After 300 seconds, the next request still gets the cached page, and Next.js renders a new version in the background. If that render fails, Next.js keeps serving the last good version. When you need an update on demand, call revalidateTag(tag, 'max'). This marks the tagged data as stale, and requests get the stale data while the revalidation runs. Next.js starts the revalidation on a request, not on the call, so pages revalidate as visitors open them and not all at once. The option { expire: 0 } behaves like a hard purge: the next request waits for a new render.

Size the platform for the worst case

Size your platform for the burst after a purge, not only for normal traffic.

  • Container memory. Measure memory use during a planned purge in a quiet period, then add headroom above that peak.
  • Redis memory. Set maxmemory on purpose. If you use replication or persistence, leave some RAM free for the buffers. The INFO memory field mem_not_counted_for_evict shows how much they use.
  • Eviction policy. For a pure cache, the Redis docs call allkeys-lru a good default. With noeviction, writes fail at the limit. The volatile-* policies behave like noeviction when no keys have an expiry.
  • Expiry. Give cache entries a TTL. Keys that expire on time are less likely to fill the cache.
  • Payload size. Smaller cache entries use less Redis memory and less network. Compress large pages before you store them.
  • Next.js memory cache. When you use a custom cache handler, set cacheMaxMemorySize: 0. Then reads go to the shared store, and each instance does not keep its own copy in memory. The default is 50 MB per instance.
  • Timeouts. Tune client timeouts after you know how the system behaves under load and during a purge, not before.

A short incident review template

A blameless review describes systems and decisions, not people. Ask what made an action look safe at the time, and what would make the safe path the easy path next time.

# Incident review: <short title>

## Summary
- Date and duration: <date>, <start> to <end> (<timezone>)
- Impact: <what users saw, on which pages>
- Severity: <P1 to P5>

## Timeline
- <time> <event, for example: cache purge started>
- <time> <first signal, for example: CDN hit ratio dropped>
- <time> <alert fired or someone noticed>
- <time> <mitigation applied>
- <time> <latency back at baseline>

## Detection
- How did we find out? <alert, synthetic test, customer report>
- Which signal showed it first? <signal>

## Cause
- Trigger: <the change or event>
- Mechanism: <how the trigger led to the impact>
- Contributing factors: <capacity, configuration, missing guardrails>

## What went well
- <item>

## What was hard
- <item>

## Actions
| Action | Owner | Due |
| --- | --- | --- |
| <action> | <team-handle> | <date> |

## Open questions
- <question>

In practice

In November 2026, we investigated a latency incident on a server-rendered Next.js storefront at an international cosmetics retailer. A cache purge let the containers build up memory and caused Redis timeouts. The team gave the containers more memory, and latency returned to its baseline.

A page cache with ISR was already planned, and after the incident it got priority. The next day, it went live with a lifetime of 300 seconds, so pages now refresh on their own instead of all at the same time after a purge. The team decided to tune the timeouts only after it knew how the platform behaves under load and during cache purges, and a follow-up change to compress the payloads in Redis went into review. Read more about our work for this client in the case study.

Checklist

  • Send a change event to Datadog for every cache purge.
  • Put the CDN hit ratio, origin requests, container memory, Redis and app latency on one dashboard.
  • Do not purge everything during an incident with 5xx errors.
  • Prefer targeted purges by URL or surrogate key.
  • Use soft purges and allow stale content in your headers.
  • Purge large sets in batches, with a pause between them.
  • Use time-based expiry for pages that can be a few minutes old.
  • Size container memory and Redis for the burst after a purge.
  • Choose a Redis eviction policy on purpose.
  • Write a blameless review with owners and due dates for each action.

For a review of your caching signals and alerts, see the frontend observability assessment.

Sources

Let's connect

Talk about your project

Tell us about your team and your problem. In 30 minutes we find out whether one of our offers fits, and if none does, we tell you.

Book a 30-minute call