Joystream / joystream

Joystream Monorepo
http://www.joystream.org
GNU General Public License v3.0
1.42k stars 115 forks source link

[DWG] Consider using Cloudflare proxy #5048

Open kdembler opened 8 months ago

kdembler commented 8 months ago

One thing I have experimented with is using Cloudflare proxy for my distribution node. In the past I have used gateway.joyutils.org which was a Cloudflare Worker function that would just proxy the request to my node. Using that has shown big bandwidth gains, but at the same time has increased latency quite a bit. You can find those results in the CDN performance report - https://joystream.notion.site/Joystream-CDN-performance-part-1-c8aff72f95ca4e86866079f81784aacb?pvs=4

Recently I've tried a simpler approach - just enabling Cloudflare proxy at the DNS level. Whenever you add a DNS record through Cloudflare, you have an option of enabling their proxy for that record. As I understand it, when enabled, all the requests are not routed directly to the backend server but rather to the closest Cloudflare data centre and then they use Cloudflare private network for the rest of their travel. This is how the enabled proxy looks like in DNS settings: CleanShot 2024-01-18 at 10 29 29@2x You can read more about it in Cloudflare docs: https://developers.cloudflare.com/dns/manage-dns-records/reference/proxied-dns-records/

Here you can see the difference in performance from our synthethic test. Without proxy: CleanShot 2024-01-17 at 10 16 25@2x

With proxy: CleanShot 2024-01-17 at 10 16 47@2x

As you can see, the difference in latency is pretty massive. I think we should consider enabling this kind of proxy for some of our distribution nodes.

Things to keep in mind:

  1. We cannot be over-reliant on Cloudflare - disruption in their services shouldn't be critical to our CDN.
  2. Requests proxied through Cloudflare would most likely come from their IP addresses which can disrupt our dashboards that gives us an idea of where our users are. We should look into whether we can somehow extract original user IP from the requests.
  3. Cloudflare can block some users, for example those using Tor network.