Skip to content
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

Experiment with Node.js Website Traffic on Vercel #3366

Closed
ovflowd opened this issue May 24, 2023 · 29 comments
Closed

Experiment with Node.js Website Traffic on Vercel #3366

ovflowd opened this issue May 24, 2023 · 29 comments

Comments

@ovflowd
Copy link
Member

ovflowd commented May 24, 2023

Hey you all 👋 as our ongoing efforts to improve the reliability and performance of the Website. The nodejs.org website codebase reached maturity for us to start the cutoff tests for serving the Website related routes through Vercel.

Useful Information

  • The Website is served on https://node-js-org.vercel.app
  • The Website is automatically deployed to Vercel by Vercel Integration on https://vercel.com
  • An ideal subdomain for this temporary experiment is https://vercel.nodejs.org

Important Notes

  • Cloudflare cache should be disabled for all routes served by Vercel. Vercel has its own caching rules, and those might conflict with Vercel-ones
  • After analysing our NGINX file, the following subdirectories should not be served to Vercel:
    • /dist
    • /download
    • /docs
    • /api
    • /documentation
    • /metrics
    • /github-webhook.log
    • /traffic-manager
  • Vercel should serve all other routes

Miscellaneous Information

  • In the future, api/ should be served by the website, as the latest API docs will be served and built directly from the website repository. But that's a topic for another time.
  • Once we adopt Vercel, over time, we can update the NGINX config to remove some of thew website-specific configurations we had.
@targos
Copy link
Member

targos commented May 25, 2023

As a first step, I created the DNS entry:
CleanShot 2023-05-25 at 12 11 43

Next: figure out how to make the SSL config happy

@ovflowd
Copy link
Member Author

ovflowd commented May 25, 2023

I guess here are some docs: https://vercel.com/guides/using-cloudflare-with-vercel

@ovflowd
Copy link
Member Author

ovflowd commented May 25, 2023

Pretty much:

Set the target on your CNAME to cname.vercel-dns.com instead of node-js-org.vercel.app and ensure SSL mode is set to full!

@ovflowd
Copy link
Member Author

ovflowd commented May 25, 2023

Oh, it looks like it solved by itself, @targos when I added it on https://vercel.com > settings > domains, but I guess you can still update the CNAME so it becomes happy (and agnostic to the default .vercel.app domain)

@targos
Copy link
Member

targos commented May 25, 2023

Updated the cname to cname.vercel-dns.com.
Now for the subdirectories that shouldn't be forwarded to Vercel, I don't really know what to do.
I found this documentation, but the feature is only available to Enterprise users (which we are not).

@ovflowd
Copy link
Member Author

ovflowd commented May 25, 2023

@jasnell if you can help us out here 🤔

@ovflowd
Copy link
Member Author

ovflowd commented Jun 12, 2023

cc @richardlau let me know once you have updates :)

@richardlau

This comment was marked as outdated.

@ovflowd

This comment was marked as outdated.

@richardlau
Copy link
Member

richardlau commented Jun 26, 2023

I've added a (now corrected) Redirect Rule in Cloudflare for the URLs that should not be served to Vercel:

(http.host eq "vercel.nodejs.org" and http.request.uri.path matches "^/(dist|download|docs|api|documentation|metrics|github-webhook.log$|traffic-manager)(\\/.*)*")

image

@ovflowd
Copy link
Member Author

ovflowd commented Jun 26, 2023

Hmm @richardlau I see that the redirects would work as long as the "vercel" website is not on the main domain (nodejs.org)

As I can see that it is redirecting https://vercel.nodejs.org to -> nodejs.org

Afaik the intent is that for anything from X routes it goes to one server and the others would go to another server.

@ovflowd
Copy link
Member Author

ovflowd commented Jun 26, 2023

Pretty much the desired final behaviour is that:

  • Caching for nodejs.org is disabled except for the dist|docs|etc routes
  • All routes that do not match that regex go to Vercel DNS (or subdomain)
  • All routes that match the regex go to DgitialOcean DNS (or subdomain)

But the hand-off from one origin to another would need to be transparent, without actual 301 redirects I think. (Like a Reverse Proxy)...

cc @jasnell if you know how we can do this

@richardlau
Copy link
Member

Hmm @richardlau I see that the redirects would work as long as the "vercel" website is not on the main domain (nodejs.org)

Yes, I don't know how to get the desired final behaviour without redirects and/or subdomains. At least via the various rules (Page, Redirect, Bulk Redirect) available to us in Cloudflare.

@targos
Copy link
Member

targos commented Jul 4, 2023

As I wrote above, there seems to be a Page Rules feature: https://developers.cloudflare.com/support/page-rules/using-resolve-override-in-page-rules/
But we cannot use it as it's only available to Enterprise accounts (we have a Business account)

@ovflowd
Copy link
Member Author

ovflowd commented Jul 9, 2023

FYI: Our Cloudflare instance got upgraded to Enterprise.

@ovflowd
Copy link
Member Author

ovflowd commented Jul 10, 2023

After chatting with @targos here's the outlined plan:

  • We're making a new subdomain download.nodejs.org which goes to our DigitalOcean origin
  • For testing environment (vercel.nodejs.org) we're making all requests under these matches below to go through download.nodejs.org (it's not a redirect, but an "Origin Override"
    • /dist
    • /download
    • /docs
    • /api
    • /documentation
    • /metrics
    • /github-webhook.log
    • /traffic-manager
  • Everything else goes to the default origin of "vercel.nodejs.org"

After this test goes successful, we can present the outcome to the TSC.

@richardlau
Copy link
Member

After chatting with @targos here's the outlined plan:

  • We're making a new subdomain download.nodejs.org which goes to our DigitalOcean origin
  • For testing environment (vercel.nodejs.org) we're making all requests under these matches below to go through download.nodejs.org (it's not a redirect, but an "Origin Override"

I'm kind of confused here. Downloads should remain with the https://nodejs.org/ URLs.

@ovflowd
Copy link
Member Author

ovflowd commented Jul 10, 2023

I'm kind of confused here. Downloads should remain with the nodejs.org URLs.

They will remain. I guess the confusion here is that vercel.nodejs.org and download.nodejs.org are just references to the origins. For all intends and purposes you will see nodejs.org on your browser :)

@targos
Copy link
Member

targos commented Jul 10, 2023

The URLs wouldn't change. This would just be a hidden level of indirection:

  • nodejs.org/dist -> download.nodejs.org/dist -> DO
  • nodejs.org/en -> vercel.nodejs.org/en -> Vercel

@targos
Copy link
Member

targos commented Jul 10, 2023

I think this will make the mental model easier to understand. And in the future, download.nodejs.org may point to Cloud storage instead of our server.

@richardlau
Copy link
Member

  • nodejs.org/dist -> download.nodejs.org/dist -> DO

Does this break the load balancer we have set up for nodejs.org (Traffic -> Load balancing)?

@richardlau
Copy link
Member

FWIW Cloudflare has been mostly serving requests over the weekend from our Equinix Metal server and not the DO one.

@ovflowd
Copy link
Member Author

ovflowd commented Jul 10, 2023

Yeah, I noticed that now, but, afaik, I don't think so. The whole download and vercel aliases are abstractions. I think current rules still apply. But we also will need to double-check all our page rules. As we might need to remove some and add some simplification here.

image

Edit: Cloudflare team updated us and Load Balancers are respected.

@targos
Copy link
Member

targos commented Jul 10, 2023

We will probably need to update (or copy) the load balancer config, as it currently applies to the host name "nodejs.org".
I think creating a new host name will also help us to setup everything without touching at the production config, and make it easier to swap when we are ready.

@ovflowd
Copy link
Member Author

ovflowd commented Jul 17, 2023

All changes got applied by @richardlau.

@ovflowd
Copy link
Member Author

ovflowd commented Jul 17, 2023

Current Configuration on Cloudflare

image

@ovflowd
Copy link
Member Author

ovflowd commented Jul 29, 2023

This can be marked as done. We concluded the migration steps.

Below is a summary of the steps taken today with @UlisesGascon:

  • All existing Page rules besides the github-webhook.log one were removed
    • These rules were not needed anymore as our Middlewares on Next.js already covered what they were doing
  • The AAAA record of nodejs.org was changed to CNAME pointing to Vercel's Domain Servers
  • The DNS record new.nodejs.org was removed due to being obsolete
  • The DNS record blog.nodejs.org was updated to use Proxied Traffic by Cloudflare
    • A Redirect Rule for blog.nodejs.org was made to -> nodejs.org/blog/
  • The Origin Rule for Vercel Traffic was updated:
    • Pointing to origin.nodejs.org instead of nodejs.org
    • The vercel. prefix from vercel.nodejs.org was removed
    • foundation.nodejs.org and benchmarking.nodejs.org were added as part of the Origin Rule (so their traffic goes through origin.nodejs.org
  • The Load Balancer configuration was updated by using origin.nodejs.org as the Hostname for the Load Balancer
    • A new Load Balancer was added; the original one is disabled and can be removed.
    • The new load balancer uses the same Pools and the same rules as the original one
  • A Cache Rule was created to cache all non-Vercel paths
  • Cache Reserve was enabled on the account to store all cached paths into Cloudflare's R2 Storage
  • The outdated Vercel Redirect Rule was removed (as it was never used)
  • The vercel.nodejs.org DNS record was removed as it is not needed anymore

We've monitored traffic and tested common and edge scenario paths and everything seems to be working fine.

@ovflowd ovflowd closed this as completed Jul 29, 2023
@ovflowd
Copy link
Member Author

ovflowd commented Jul 29, 2023

Also, a note that the Webhook on nodejs.org website for rebuilding the Website on DigitalOcean's server on every push got disabled. (I've disabled the repository settings).

So this should also solve some of our current traffic pains.

@ovflowd
Copy link
Member Author

ovflowd commented Jul 30, 2023

Today we had a little incident, since Cloudflare was caching Vercel-paths, because we forgot Cloudflare's default behaviour is to cache everything.

This led to one of the Website rebuilds to Cloudflare to cache legacyMain.js from the Website build exactly during the rebuild, causing a corrupted empty file to be cached.

This led to: nodejs/nodejs.org#5568

We've fixed this by forcefully telling Cloudflare to not cache Vercel paths as Vercel requests should be served directly by Vercel at all times. The Cache Rule we configured is as shown below:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants