Operationalizing Node.js for Server Side Rendering (2018)
medium.com
medium.com
(Keeps reading...) Ah, about halfway through the article they talk about introducing multiprocessing using the `cluster` module. But then they say the process is tied up until the request is fully received, bottle-necking the process based on client speed, which is not how I understand Node to work at all. Sure, the slow connection will tie up a socket and memory, so a buffering proxy makes sense, but it shouldn't affect compute. Maybe it's a limitation of `cluster`? My experience is with `worker-farm`.
Which brings me to the second oddity: CPUs are fast. What is Airbnb doing that takes so much compute? Perhaps server-side React is slow? On my own, admittedly low-traffic Node site, I use jade/pug for templating, and the initial template compile step can be expensive. But then I cache the compiled template and everything is too fast to care about thereafter.
I don't doubt that they had a problem, or how they fixed it, and I enjoyed this deep dive. Nonetheless, their reasoning about the underlying causes don't ring true for me.
I'll read the article and come back on your other points :)
personally never used clustering and the cluster module (we did that at haproxy lvl with containerised individual node processes), but I think that's exactly what he's saying, that the cluster module is the limitation (https://nodejs.org/api/cluster.html). not sure how they use it but it seems to imply requests being fully read in the cluster PID than passed to the workers
Anyway, it’s interesting how they separate the code for fetching data (making it a responsibility of one server) from the code for rendering data (making it a responsibility of another, Node-based, server). Which means that although they re-use the code for components, the code for data fetching logic must get duplicated.
In my experience, the rendering server has a copy of the SPA mounted. I'm not aware of any normal reasons for duplicated fetching logic.
I don't get point 2, if they are to 'hydrate' the react renders in node with data, they have to have a 'fetching' logic in there, the fact that it connects to an 'API' instance makes no difference, the client could use the same connection with same logic client side.
The way I am understanding their blog post, they have a dedicated server (let's call it server1) for api requests, and then a server for rendering (let's call it server2). Server1 does all the fetching logic and then sends the received and appropriately processed json to server2, which needs only to use this data for rendering.
That means the same code can be used both on the server and client: the description can be used to render to an HTML string, or to create and update client-side DOM nodes.
(React isn't special in this regard anymore, other modern web libraries have taken what still look like old-school templates but stopped using HTML strings as their immediate target.)
The main advantages to backend-only templates would be if your website really doesn't benefit from an SPA or if your code is mostly already written.
Erm. In what way? Ubiquity? Code quality?
Yes :-)
Statefulness of a component is not useful for server-side rendering anyway, because component state will only change on the client side. But yes, stateful components work both client-side and server-side.
> And what about a todo-list like the one on the react start page, will it "magically" use hidden forms and make http posts to update the server state
I am not sure what you mean. Filling in and submitting a form only makes sense on the client side. It can be pre-populated with data during server-side rendering though. Naturally, http requests for form submission will work on the client.