-
Notifications
You must be signed in to change notification settings - Fork 27.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RSC and CDN interaction makes next.js inefficient for highload projects #65335
Comments
@dankain This is what I get on the latest canary (after doing these exact steps).
Can you confirm if you are seeing the same on the latest canary? → |
Yes I have tried on the latest canary and it is the same. You need to go to category 1 and then category 2. Above I just see the navigation to category 2. If you go to both categories you will see there are 2 different rsc requests for the same product data |
Hi @samcx I have created a video to explain RSC.CDN.GH65335.mp4 |
For some context, the The reason the
This is obviously not a solution to the issue you're describing, but I wanted to provide some color as to why app router is doing this. If those responses are cached, and the RSC data for a page returns a tree that corresponds with the request from a different page, things will start behaving incorrectly. For example, see: |
Thanks @ztanner , that helps with the context. Partial rendering is a great concept, but if it means I can't use a CDN effectively then that is an issue. The problem with the If this is not possible do you have a suggestion on how to deploy next for a global site? Our site is hosted in Europe, but has southern hemisphere customers. Do I now need to somehow push the page building, HTML cache and data cache to an edge location? |
Experiencing the same issue, wherein identical RSCs produce different hashes when being Without diving into the details of If so, is there a world where we decouple them and have, say, a On a high level:
The two paths fetch the same The goal would be to achieve caching of the data part of the _rsc payload across all paths (it's the more expensive one, presumably), and then the tree part of the _rsc payload can be cached per path. |
This comment has been minimized.
This comment has been minimized.
As a cache-busting workaround for a subset of broken third parties, I don't see a good reason not to offer an option to disable it. |
With proper CDN/proxy configuration, one should already be able to ignore Maybe changing request flow and cache header logic (Vary...) to allow a decent cache hit ratio by default on CDN, proxy and browser. Or maybe documenting cache processing/response construction on |
If I understand correctly, RSC payload not being cached by the CDN nor by Next's caching system means interception routes (and parallel routes) are broken after deployments unless the whole cache is cleared. I implemented a modal with interception + parallel route, which breaks down into a full page load because the RSC payload hash has changed, and the old hash is no longer served by the new build. To keep the modal working, I have been clearing the (CDN) cache after each deployment. |
Hi @samcx , trying to get an understanding on where you are on this. Could you please give me an update? Trying to understand whether the app router approach is suitable at all or it it's limited to only be used without a CDN. This will help me understand whether I should move (or stick) with the app router or carry on with the pages? Thanks. |
I'm in the same boat I think. Running a high traffic, self-hosted ecommerce site with 100ks of products which are linked to from many different places. CDN caching is crucial - hitting the next.js server should be an absolute last resort. If I'm understanding things correctly, it seems like the app router essentially breaks all CDN caching because the RSC request/response for a page is slightly different depending on where you're coming from. I'm still processing all the info here but I'm starting to think I will have to stick with the pages router. |
Hey folks - we're working on a router refactor that aims to address this issue as well as others related to the current router prefetching behavior. The new implementation will no longer require the We'll share more as we get further along, just know that this is actively being worked on with high priority. We are aiming to improve the cacheability of these responses and improving the transport layer so the router only needs to request information it doesn't already have. |
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/rsc-test-m43xq4
To Reproduce
Current vs. Expected behavior
Current Behavior
Product 1 appears in category 1 and category 2
Currently they return return identical data, but have a different
rsc
hashExpected Behaviour
If the data is the same there should be only one
rsc
hash.With a high throughput global ecommerce site I want to cache identical data close to the customer in a CDN. The different
rsc
hashes mean that I will get CDN cache misses and traffic will have to go back to the server, potentially a distance from the customer and with a slower response time.Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 Available memory (MB): 65536 Available CPU cores: 10 Binaries: Node: 18.18.0 npm: 10.1.0 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 14.2.3 // Latest available version is detected (14.2.3). eslint-config-next: 14.1.0 react: 18.3.1 react-dom: 18.3.1 typescript: 5.4.5 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Performance
Which stage(s) are affected? (Select all that apply)
next start (local)
Additional context
Hi I'm trying to work out how I make the RSC requests work with a CDN when self hosting Nextjs. Is there any more info on this subject. I'm working on an ecommerce site with 100,000 products. Those products could appear in numerous product listing pages (search result pages). Each of those PLP pages are given unique URLs for SEO purposes. Take for example the following URLs:
/mens/
/mens/trainers
/mens/trainers/brand
/mens/trainers/brand?facet-price=%3A168
They could all have the same products in. Due to the way the rsc hash is calculated that means I get a different _rsc params on each listing page, even though the contents of that response is exactly the same.
product/299336/?_rsc=1vl30
product/299336/?_rsc=qe3go
product/299336/?_rsc=1vg99
product/299336/?_rsc=1stsw
I have even gone to different areas of the site cart, checkout, order history, all with links back to the same product, they each produce different _rsc params, but still the data returned is identical?
On a high throughput site I want to be able to cache identical data in the CDN close to the customer. At the moment that would be impossible as there would be to many variations on the rsc hash to make the caching effective.
For solutions I think I only have 2 options:
Cache all rsc requests in the CDN - this would end up caching loads of duplicate data and get cache misses when they should be hits
Pass all request through to the Nextjs server. - With this solution I would worry the server would be overloaded at peak periods.
In both cases there would be an extra cost to the client
I'm trying to understand why the rsc has is different when it is always returning identical data? What is the purpose of this hash? As mentioned before could this just be set to _rsc=1? We would also have issues with the Vary header as it is currently returned like this:
Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url
In this case the Next-Router-State-Tree and Next-Url will be set on where you are coming from and do not necessarily have an impact on the data need for the page we are going to. The Vary header will again have an impact on the CDN
This issue has been rasied in the following discussion thread #59167
NEXT-3327
The text was updated successfully, but these errors were encountered: