Only 1/2 of the API requests are served by cloudflare cache, the other half are not

What is the name of the domain?

midly.it

What is the error number?

no error number

What is the error message?

no error message

What is the issue you’re encountering

Hi, I have a few cache rules, one for each endpoint of my web app where I need to cache the response (mainly 4 of them so far), and those endpoints are public (meaning the users are not require to be logged to access them); what happens with the cloudflare cache is that only less than half of the requests are cached on those specific endpoints, while more than half of them are served by the origin. Usage of cloudflare cache is critical for our business, and we experienced a major downtime of our app because the cache didn’t work as expected (it happened what I just described so far, hence our DB was overloaded with requests and it went down for hours). During our previous previous events the overall load on the app was less noticeable, but this schema I just described happened everytime, with the same pattern. I want 100% of the requests to be served by the cache, how do I achieve this?

What steps have you taken to resolve the issue?

  1. analyze my backend logs, nothing noticeable came out
  2. write to the Cloudflare assistance; I switched to Business plan just to have the 24/7 assistance and ask them to help me, I never got replied.

What are the steps to reproduce the issue?

Bring batches of 30K-plus-simultaneous users on my website and look at the cloudflare dashboard…

Without you giving some example endpoints it’s hard for anyone to check.

You need to start by understanding the default cache behaviour, what will be cached and what won’t be…

Then you can change that behaviour for your use case by using cache rules…

Also note that caches are local to the Cloudflare data centre, if a request comes through from another data centre due to a different user’s location, then another request will go to your origin. Look at tiered caching to help with this…

2 Likes

Hi, thanks for responding.
So you can navigate this page of my web app for example: Midly

You don’t need to be logged.

This endpoint is cached in cloudflare on this page is:
https://midly-artists.midly.it/api/artists/public/leader-board/billie-eilish?page=1
The page param is for data pagination, and all the pages should be cached; you can experiment this simply by scrolling the interface, the scroll should trigger the api call to ?page=2, ?page=3, etc (for pages > 3, you need to be logged, but I don’t think that’s the point).
I expect the response of this endpoint to be cached on cloudflare, and to be served from the cache and not from the origin, but when I look at my cloudflare dashboard I see a 50/50 split: about 50% of the responses are served by origin, about 50% are served by cloudflare during the same time span.

Does this help you to guess what could be happening?

Thanks again for the help.

How many actual requests is that? The max-age is 1 hour so if it there’s not many users it may be the cache is expiring and/or your requests are spread across data centres.

When I request the page, I get a MISS, then HITs continously so the cache behaviour seems normal.

1 Like

This topic was automatically closed after 15 days. New replies are no longer allowed.