Live data from Hacker News

The absurd complexity of server-side rendering

gist.github.com

51–60 of 395 posts

Re: The absurd complexity of server-side rendering

#51
I find this a very insightful application of the concept of colours to look at the problems of mixing code meant to run on slightly different and subtly incompatible runtimes, within the same code base, without calling out this distinction of "colour" by any particular mean of syntax, or tooling, or explicit documentation.

It's a good observation that helps, at least me, shed light and give a name to this problem that many will have experienced and struggled with.

Re: The absurd complexity of server-side rendering

#52
post #44
post #41

Since the post mentions Next.js, it's worth calling out two streams of ongoing work that solve major painpoints of SSR: 1. A filesystem convention (`*.server.ts`) for more cleanly separating client and server component trees 2. The introduction of a Web standards runtime[1] for SSR. If anything, we're entering the best generation of SSR ever. We'll see new generations of apps shipping less JS to the client, rendering…

Is it believed that you'll do less overall compute and bandwidth if you use serverless functions to execute (parts of your) client, in place of sending static bundles to the client and letting them execute it? I don't really get SSR. Isn't it more desirable to have more of the compute required to render the client done by the client machinery? I view this both as true in corporate and public web scenarios, surely it'…

Not really, because any JS/HTML logic that you have needs to be downloaded into memory and compiled and interpreted by each client independently. Then, once loaded, any server-side data needs to be fetched from an API request and injected into the page in the proper place. Server-side rendering saves at least one round trip by fetching the data from the database and injecting it on the server side before sending the fully compiled HTML + CSS + JS as one static file.

So you have to have some server-side logic regardless if you have the need for server-side data. The small amount of memory and compilation overhead by the server-side rendering function is more than made up for by the time saved on network latency. It's just not a significant amount of computation regardless.

Importantly, the server-side is not loading a full DOM into memory before sending it down the pipe. It's just interpolating the resulting HTML/CSS/JS as if it were static after fetching the prerequisite data.

Re: The absurd complexity of server-side rendering

#53
post #7

Earlier quoted context omitted.

And usually leads to a BBOM architecture

I have colleagues using Laravel, and there's nothing muddy-ball about their apps at all. Their code is tidy, modern, readable, and clearly maintainable. In terms of practical effect, frameworks influence developers more than languages do.

When people say they use "PHP" for webdev I recall BBOMs of flat files and raw SQL. Historically speaking, "PHP" does not necessarily imply "PHP+Laravel" or any other sane framework.

OTOH if someone says they use "Python" for webdev I assume Flask/Django/etc.

Re: The absurd complexity of server-side rendering

#54
post #44

Earlier quoted context omitted.

Is it believed that you'll do less overall compute and bandwidth if you use serverless functions to execute (parts of your) client, in place of sending static bundles to the client and letting them execute it? I don't really get SSR. Isn't it more desirable to have more of the compute required to render the client done by the client machinery? I view this both as true in corporate and public web scenarios, surely it'…

Not really, because any JS/HTML logic that you have needs to be downloaded into memory and compiled and interpreted by each client independently. Then, once loaded, any server-side data needs to be fetched from an API request and injected into the page in the proper place. Server-side rendering saves at least one round trip by fetching the data from the database and injecting it on the server side before sending the…

> Not really, because any JS/HTML logic that you have needs to be downloaded into memory and compiled and interpreted by each client independently

I see my question was unclear. I did not mean compute/bandwidth "in totality", I meant "in costs that would be invoked by the application owner".

> Server-side rendering saves at least one round trip by fetching the data from the database and injecting it on the server side before sending the fully compiled HTML + CSS + JS as one static file.

Sure, but the first hit would've been a cache hit anyways.

> The small amount of memory and compilation overhead by the server-side rendering function is more than made up for by the time saved on network latency

I don't really believe network latency would play in here. CDN would have the static bundle "at the edge" already for you. Static content is very easy to serve and break up into cacheable components for clients too, the Edge isn't really a revolution in that space. It's also unfair to present Edge functions as always-hot in terms of latency here, again I imagine the cost invoked for such features must be so high for so little gain

Re: The absurd complexity of server-side rendering

#55

Earlier quoted context omitted.

Thus, you are confirming there is a hugh level of complexity. I want to add something else on top of what's in that gist: ssr is slow, rendering an application twice (on server and client) is just slow. We only do that for cache and seo, every other page suffers.

I'm not sure what about two bundles causes a huge level of complexity. Granted, I use Next.js, it does all of this out of the box. SSR is fast, it's provably faster than client side rendering for first load. You can optionally do client side hydration, so the time to meaningful content is fast from SSR, and subsequent page loads are done SPA style (if you want). It's never a fair comparison, but Stackoverflow is enti…

> Also, all forum software, which is SSR, despite being 20-30 years old, is usually faster than a SPA.

Only because crap tons of hardware got thrown at the problem.

I remember when forums were multi-seconds to load each page. It sucked.

People complain about reddit a lot, but even on mobile, the reddit website is fast. It may be janky at times, but navigating between comments on stories is under a second, loading more comments is, well, not fast, but quick.

Hacker News is notably one of the few non-crap forum sites out there. phpbb used to be everywhere, and it sucked everywhere. Up until 2012 or so, the old dial up BBSes from the mid 90s had a better user experience than the latest and greatest internet forums. (of course BBSs only had 1 client at a time, a much easier problem to solve!)

And yes, phpbb works now, because now a cheap host has an SSDs with gigs of RAM. To do the equivalent of a what a 486 running DOS did back in 1993.

Re: The absurd complexity of server-side rendering

#56
post #11

I've been saying it for years - the hard part is not "server side" vs "client side", it's making sure the state stays consistent between those 2 buckets. If you want to remove the hell from your life, you need to be all in on one or the other. For us, we've been keeping all state server-side using things like Blazor and hand-rolled js-over-websocket UI frameworks. We never have to worry about more than ~10k users, so…

The right model for attacking this problem is multiplayer video games. That is the technical space where the questions of synchronizing a shared concept of what the universe should look like among multiple distinct nodes separated in space and time with real-time latencies has been thoroughly investigated.

It is also some of the more complicated and intricate code that you will find in the wild, so best of luck.

Re: The absurd complexity of server-side rendering

#57
post #17

I opened this thinking it would lament the challenges of server side frameworks and templating. But those things seem so, so sane and simple compared to the mess I just read about. It's worse than I could have imagined. Who thinks that's a good workable solution? Who's idea was this?

Adtech needs a lot of JS to work. JS to determine how long they are hovering over this and that element, how long this or that ad is in their view, and so on and so forth. The logical conclusion is that every single HTML element needs to be wrapped in a bit of JS somewhere. Nothing should happen in the users browser that can't be monitored by JS.

So adtech is ruining the web. Everything makes sense now.

Re: The absurd complexity of server-side rendering

#58

There are cases when server-side rendering (without SPA) is easier and faster. For example: documentation sites, blog-like sites, internet stores, sites like Hacker News. In all these cases, you can save on development time by writing just one application instead of two (server and client), and improve performance (no need to load multimegabyte JS applications and make multiple AJAX requests to display a page). Of co…

In my experience (having implemented React SSR a few times for different companies) it's usually applied halfway between the two, on simpler form-driven websites - process-driven screens, marketplaces, the kind of places where you want either the performance improvement of a prerender or the SEO friendliness.

Re: The absurd complexity of server-side rendering

#59

SSR feels like an echo of JSF (that's JavaServer Faces for you youngins) - an exceptionally complicated way of doing simple things. IMO, SSR will follow the same arc in history - a brief period of popularity, followed by a lot of "what on earth were we thinking". Client side rendering is much simpler and cleaner.

SSR is generally for SEO and performance

If you need SEO and (to a lesser degree) performance, you're likely serving content rather than an application and likely could've done with SOR (a new moniker I've come up with, Server Only Rendering).

Re: The absurd complexity of server-side rendering

#60
post #39

The common mistake teams make getting started with server-side rendering for React is thinking that your entire backend has to be contained in a single JavaScript bundle. Instead, use any language you want to set up your APIs and business logic. Then set up a fully independent pool of servers running Node.js whose only job is SSR. This setup skips over every problem the author mentions.

The newest versions of Next.js have API routes that are independently deployed as serverless functions, so they do not interfere with the SSR instance.
Post reply on HN