3 ms·
Node is not designed to be multi-tenant. That is, it is expected that a single Node.js process runs a single Node application. Additionally, Node does not attem
by kentonv 5y ago
Node is not designed to be multi-tenant. That is, it is expected that a single Node.js process runs a single Node application. Additionally, Node does not attempt to provide any isolation of that application -- it is assumed that the application code is fully trusted.
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/ https://www.infoq.com/presentations/cloudflare-v8/
(I'm the lead engineer for Workers.)