Migrating from Netlify to Cloudflare Workers Sites for 2x Performance (2020)
brianli.com
brianli.com
Why not just use Cloudflare's standard CDN? It makes no sense. By this logic, a file system is a perfect key value store, because ya know, the key is the full path and the file is the value.
They're not wrong.
I'm still waiting for people to rediscover (fast)cgi as the "worker" interface.
The problem is that node is not a good cgi engine.
Since node is so dominant for serverside js, fastcgi with javascript is very uncommon.
PS: I do not know whether deno is better for fastcgi, but it is unlikely that it would be good enough.
Also I am not an expert so I will not be able to prove anything, but I can try my best to express my opinions.
I do not think that node has any problems with FastCGI
So basically Node's start latency are too slow for CGI and FastCGI is bad for a worker platforms (or for any multitenant offering).
The reason is that cloudflare doesn't want to keep track which workers are for which customers and want to offer a clean slate environment for each request.
This either means spinning up new processes or using some other in-process isolation techniques. All javascript workers platforms I know use V8 isolates, which (I believe) node does not offer.
PS: I made also another mistake, it looks like deno offers a worker platform on V8 isolates. https://deno.com/deploy
So, in order to host Node apps on behalf of multiple customers, you must run multiple copies of Node.js as separate processes, and you must use some sort of secure containerization or VMs to isolate them from each other and from the system.
That in turn means there's a lot of overhead involved in running each application instance. To amortize that overhead, it's necessary for each instance to handle a large number of events, so that the per-event overhead is reasonable. So, you need to concentrate your traffic stream onto a small number of instances.
Workers, however, had the design goal that every application would run at every one of Cloudflare's hundreds of locations, in order to run as close to the end user as possible. That implies that there may be hundreds of instances of an app around the world, while each instance only handles traffic from a particular locality, which may be small. This means the setup overhead per instance had to be much less, and it had to be possible to run tens of thousands of live instances per machine, with the ability to quickly load from a library of millions on disk on-demand.
That's just not possible with containers, or even processes. But it is possible if you run lightweight V8 JavaScript instances -- called "isolates" -- all inside a single process.
This talk of mine goes into a lot more detail: https://www.infoq.com/presentations/cloudflare-v8/
(I'm the lead engineer for Workers.)
Cloudflare Workers and KV @ the Edge can do a lot to manage the control plane.
Using Python for Workers was weird, and it felt like you needed to be both a Python and JS expert to make it work.
$ dig +short brianli.com
76.76.21.21
$ whois 76.76.21.21 | grep OrgName
OrgName: Vercel, Inc[1] https://developers.cloudflare.com/pages/framework-guides/dep...
They ARE a big cloud provider.
* build the website and produce a GHA artifact packaged as a zip or somesuch;
* invoke Pages deploy hook API endpoint;
* within cloudflare pages run a (e.g. python) script to download the artifact, decompress it and place the resulting files in the correct output directory.
Ideally these kinds of gymnastics wouldn't be necessary and it would be possible to just run something like `cfpages deploy .` but it is not absolutely impossible to get something working, either.
Presumably Pages was created because they saw a lot of people using Workers and KV for this use case.
The blog is on Vercel now.
$ dig brianli.com @dns.google +short
76.76.21.21
(76.76.21.21 is Vercel's vanity IPv4 address)
I don't understand the value (or hype) of Netlify if Cloudflare has many PoP (Points of Presences) and is effectively way faster.
Netlify looking similarly like an expensive Heroku (more PoP only on enterprise plans) which doesn't seem like a global network to me.
Curious to know is anyone on Netlify considering moving or staying?
If you need to perform a fast update or rollback, it does take its time.
Edit:
See this thread where I lamented on being forced to deploy from Github:
For example, our hobby React SPA deploys on merge using Actions. It also has dynamic opengraph tags for pretty Discord embeds using CF worker.
- Netlify doesn't support Range headers which means you can't host clickonce installers for windows apps there
- Vercel doesn't support IPv6 which really is table stakes these days
- S3 + CloudFront are very low-level and the bandwidth is expensive
- CloudFlare supports targeted harassment so dropped for moral reasons
I don't know about first two but S3 or CloudFront is from Amazon which certainly have too many blemishes. Also, AFAIK Cloudflare is an infrastructure provider so, I wonder why would ethics come here.
Are we going to blame Google for making a browser that is used for hundreds of immoral things?
The only reason I think one will disdain over Cloudflare is due to monopoly. And, many argue they do some DDOS attack, but I have never seen any modicum of evidence.
Google browser is not in the same situation because the abusers are not direct, paying customers of Google and Google is not fighting to both keep them and hide their identity.
I understand why CF would want to keep their privacy position. But once they know about the abuse and don't drop those customers - they support the abuse.
Cloudflare is faster, you also get http3 over http2. Also Cloudflare has much better peering around the globe. When I do traceroute it's fewer hops compared to Netlify. I have tried vercel but haven't tested it extensively they use AWS and Cloudfront. If you use Github pages or Firebase hosting they both use Fastly. Fastly is also really good, in certain regions Fastly has better peering with ISP over Cloudflare. At Least where I am located Fastly is faster, but both Github pages and Firebase hosting doesn't have support for http3. On a fast network between h2 and h3 you won't find much difference. On a unstable or slow network h3 makes a big difference.
Vercel deployed in 3 minutes and is 2-4x as fast to load for me: https://thelounge-github-io-jwd9o31su-mleiter.vercel.app/
versus 7 minutes building/deploying on netlify: https://deploy-preview-259--thelounge.netlify.app/
For example can you move a Next.js site that leverages Incremental Static Generation to Cloudflare. I wonder if ISR is even possible out of the box without you having to setup complicated caching logic anywhere besides Netlify and Vercel.
Edit: I'm an idiot, you work for Cloudflare, lol - I thought you were just particularly sharp-eyed
I'm just imagining what would happen when would also provide managed Postgres in the same easy to handle and affordable manner as their other services.
Customisability is AWS/GCP's strong suit, but as a corollary they don't make it nearly as easy to 'paint within the lines' - which is an odd UX stance to take when, by definition, 99% of your customers fall within the 99%. Personally I would have designed it to be 'simple by default, configurable if you need it', but far be it from me to say what's best.