Unexpected Spike in Next.js Image Cache Reads/Writes

Issue:
Image cache reads and writes have unexpectedly spiked from zero to around 4k per day, despite having only ~10 users daily. No recent changes were made to the codebase. The app is built with Next.js.

Request:
Looking for insights into what could cause this sudden increase in image cache activity and how to diagnose or resolve the issue.

Additional Context:

  • Using Next.js with next/image for image optimization.
  • The issue appeared without code changes.
  • Traffic has remained consistent at ~10 users/day.

Any suggestions on what to check or potential causes would be appreciated!

Im having the same issue

I’m having the same issue for both read and writes as of Feb 18 with no code changes.

I’ve changed my tags from Image to img as a temporary workaround.

1 Like

Seeing the same thing with the same Vercel / Next combo and also without any code changes, did anyone find anything out?

Hi folks, sorry that this was confusing. We’ve recently started tracking these metrics and that’s why it is 0 before Feb 18.

You can read more about it on the changelog:

We also have this documentation to help you with Managing Usage & Costs for image optimization.

I hope this was helpful.

Hey @anshumanb, I’m experiencing the same problem. ~20 users, around 75 images in total and this metric exploded within a couple of hours. I set minimumCacheTTL: 2_678_400, // 31 days in my next.config.ts but it didn’t seem to work. Is there any other way to prevent this from happening?

Hi @bartekczyz, thanks for reaching out here. Did you check using the Open in Observability to see which images are causing higher requests? Maybe that helps us narrow down the scope.

Hi @anshumanb :slight_smile: Yes I did, but there was nothing suspicious about it. In this case ~182 photos being transformed 1-3 times, but it was written to cache ~25k times :worried: I cant’t figure out the math behind it.

I see. Can you share the project ID so we can dig in further?

Hey @anshumanb, any news on this one?

Hi @bartekczyz, I’m sorry. I forgot to follow up on this one. I’ll check with the team quickly. Thanks for sharing the requested information.

1 Like

Your images are being transformed from about 2MB to about 1MB (see the Transformed Size).

The transformed size is then cached and billed per 8KB for once cache write unit.

So a 1MB image would incur 125 cache write units, or 22750 write units total. That is very close to the 25K units you’re seeing and the rounding error is likely that those images are over 1MB.

My suggestion is to lower the quality prop to compress those images further or adjust the width.

See more ways to lower your bill here: Managing Usage & Costs

Thanks @styfle for your reply.

So a 1MB image would incur 125 cache write units

Ok now it makes sense, or at least math is correct now. Please update your docs and explain what a cache write actually is, I thought it’s a single image being written, turns out it’s each 8kB of every image. Well, that’s not ideal, gonna have to think of some other solution.

1 Like

Great, glad the math is correct!

The docs mention the 8KB units in the definition here:

Image cache writes: The total amount of Write Units used to store the cached image in the global cache, measured in 8KB units. It is billed for every cache MISS and STALE.

1 Like

Yeah I dug a little deeper and found this thing as well. Thanks again for pointing me to the right direction