T
TanStack6d ago
rising-crimson

API call extremely slow in production but works fine in development

I want to fetch a list of products from our hosted server and display it in the frontend. In the development environment, the API call works as expected. However, when I run the production build (either locally or in prod), the same API call takes more than 10 minutes for unknown reasons. I’m using Next.js with TanStack Query.
3 Replies
unwilling-turquoise
unwilling-turquoise6d ago
Is the actual network request that is being made the thing that takes a long time? If so, this isn't really query related, since query just handles the states of a promise. Perhaps someone knows the answer. Since this is an extremely generic question "my endpoints take a long time in production", it would likely be best to provide a minimal repro since this is very likely domain specific
rising-crimson
rising-crimsonOP4d ago
As I said it takes a long time in prod only, so it's not query related The problem is that nextjs fetch cache sometimes fails to work as expected in production, causing repeated api calls instead of caching the result, this can lead to hundreds of thousands of unnecessary requests , drastically increasing response times in production. Such cases are handled by default by usequery in development environment, in the meanwhile usequery provide very strict rules in production
ratty-blush
ratty-blush3d ago
App or pages router? nextjs fetch cache sometimes fails I assume this is about next extension to fetch api to provide server-side caching, useQuery has nothing to do with next server cache. meanwhile usequery provide very strict rules in production what rules are we talking about? The only thing that comes to my mind, is that link prefetching just sort of DDoS your data source, it would affect only prod build as link prefetching only available in the production env

Did you find this page helpful?