News for hackers. Stuff that matters.
Re:The future of web software is HTML over WebSockets by keithwhor on Thursday February 25, 2021 @02:49PM (#26267350)
I’m gonna be “that jerk on HN,” but this is that idea that just keeps getting rehashed every couple of years then fizzles out. The reason that it’s so attractive is because as developers we love to build and save time, and we think, “imagine what we could do if we didn’t have to ask for data from remote servers...”

The problem is that stateful connections suck and create artificial complexity when you don’t need them. Instead of managing the state of your app you’re now managing the state of your app and a connection to a remote server. HTTP is a stateless protocol on top of a stateful socket connection. It wasn’t designed this way by accident.

I’m all for new engineers building SPAs creating exciting new libraries, but HTML-over-websocket has been rehashed at least three times over my professional career so far and it’s not even that long.

Don’t get me wrong — websockets have their use cases. Multiplayer online experiences pretty much require them. It’s just that HTTP isn’t fundamentally broken, and by engineering HTML over websockets you’ll almost universally find yourself building protocols to abstract the state away... re-engineering HTTP in the process.

It’s certainly a fun project which I have personally worked on. But I’m not sure it has legs outside of that. Open to being proven wrong, the authors of HTTP aren’t infallible.

Re:The future of web software is HTML over WebSockets by keithwhor on Thursday February 25, 2021 @03:04PM (#26267532)
As a thought exercise;

- What happens if the client’s internet connection temporarily drops? How do you handle client reconnections and retries?

- What if the remote server crashes through no fault of your own (AWS server rack catches fire)? How do you ensure a consistent reconnection that preserves application state?

These are just two questions that HTTP + Browsers solved decades ago.

Websockets are this cool technology that seems powerful and exciting until you realize the “boring old stateless World Wide Web” was built over decades of iteration using stateful sockets as the backbone, did most of the work for you in tandem with browsers, and is ultimately a lot cooler and more sophisticated than a lot of us give it credit for.

Re:The future of web software is HTML over WebSockets by cogman10 on Thursday February 25, 2021 @03:34PM (#26267897)
Here's another one. How do you deploy a new version of your service?

Imagine a few customers open up your site and leave for lunch. Or maybe just a random crawler or bot sitting watching for some piece of information they are scraping.

These sorts of issues can be challenging with stateless connections. I can only imagine how daunting they are with persistent connections.

Re:The future of web software is HTML over WebSockets by meheleventyone on Thursday February 25, 2021 @04:59PM (#26268875)
The nice thing about persistent connections is that you know when they’ve been closed so you could literally signal that the connection was going down for a deployment and close everyone’s connection. Clients can retry the connection until it comes back up or use another service to monitor the status.

Games basically do this routinely.

Re:The future of web software is HTML over WebSockets by rootusrootus on Thursday February 25, 2021 @05:58PM (#26269423)
But you can do that sort of communication already with existing websockets, without trying to add the complexity of pushing all your regular traffic over that link.
Re:The future of web software is HTML over WebSockets by madeofpalk on Thursday February 25, 2021 @06:29PM (#26269715)
Well, this problem exists at the moment. To be honest sockets is one approach to fix it.

What happens if a webpage is loaded over plain old HTTP and then over lunch a breaking change is deployed. The page the user loaded before lunch is now no longer compatible.

Re:The future of web software is HTML over WebSockets by mikeryan on Thursday February 25, 2021 @11:15PM (#26271303)
Compatible with what?

It’s stateless. If the api changes from underneath and you’re polling or something, then just show an error, have the user refresh the page and move on. Or use any of the various api version mechanisms for backward compatibility. It’s not an easy problem but it’s a fairly well understood and managed one. Solving this kind of known problem isn’t, to me, a very compelling case for HTML over sockets.

Re:The future of web software is HTML over WebSockets by bitsen on Thursday February 25, 2021 @05:43PM (#26269271)
I bet your ass that at least half of the developers reading HN don’t have caching of JS fully figured out such that when the JS changes server-side and immediately needs reloading on the client side that it does then and there instead of on the next request, the next page refresh, or never because they’ve f’d it up.

With server-fed, event-driven pages, you could potentially force refresh.

Re:The future of web software is HTML over WebSockets by galaxyLogic on Friday February 26, 2021 @02:01AM (#26272051)
I leave the browser waiting for a fetch-response from the server. The server responds only later when the page that is open in the browser was updated on server. Seems to work much of the time, but sometimes it seems Chrome closes the connection after a timeout and shows a network error in the dev-tools. FireFox not.

I assume web-sockets could make it work more robustly.

Re:The future of web software is HTML over WebSockets by lootsauce on Thursday February 25, 2021 @10:45PM (#26271167)
my solution to version changes in a rest api is to sent a version header with every response, the app checks it and if it does not match reloads the page, thus loading the new js.
Re:The future of web software is HTML over WebSockets by mikeryan on Thursday February 25, 2021 @11:17PM (#26271317)
I would not accept your wager. That being said if this was a “really big problem” I’d bet you that most developers on HN would have an idea how to address it.
Re:The future of web software is HTML over WebSockets by m00dy on Thursday February 25, 2021 @04:32PM (#26268597)
it is called hot-reload.
Re:The future of web software is HTML over WebSockets by conradfr on Thursday February 25, 2021 @04:56PM (#26268843)
You restore the state like you would on a SPA or regular server side rendered page.

A crash or someone hitting refresh on his browser is not that different in this respect.

Re:The future of web software is HTML over WebSockets by m00x on Thursday February 25, 2021 @09:15PM (#26270764)
I'm astonished that people are asking these questions while there's obvious answers like this.

WSs aren't a magic wand, they just allow you to do more with the same.

Re:The future of web software is HTML over WebSockets by Kranar on Thursday February 25, 2021 @09:57PM (#26270953)
I don't see what's astonishing about it and I'm scratching my head asking the same question. If the answer is that you handle disconnections and reconnections the same way that the HTTP protocol does it, then what's the purpose of HTML over web sockets?

You basically end up with a half-assed, buggy, and potentially insecure reimplementation of HTTP running over web sockets running over HTTP at that point.

Are you going to do session management and identification by issuing a unique identifier as well? Is that unique identifier going to be valid in perpetuity or have a an expiry date? Is it going to be valid and secure across all sub-domains or will it be prone to cross site scripting attacks?

Re:The future of web software is HTML over WebSockets by coldtea on Friday February 26, 2021 @01:13AM (#26271811)
>I don't see what's astonishing about it and I'm scratching my head asking the same question. If the answer is that you handle disconnections and reconnections the same way that the HTTP protocol does it, then what's the purpose of HTML over web sockets?

The purpose is in the things explained well in TFA: single source of truth, no replicated state, simpler development, and so on...

Who said the purpose would/had to be in handing "the server caught fire" scenarios?

Re:The future of web software is HTML over WebSockets by conradfr on Friday February 26, 2021 @04:27AM (#26272919)
The purpose is to render your page the "old way" but having the dom updated like an SPA.

It works for certain things and not for others. So, it's not "the future of web software" like the title says, it's one additional possibility for when it makes sense.

Re:The future of web software is HTML over WebSockets by ricketycricket on Thursday February 25, 2021 @11:14PM (#26271295)
> then what's the purpose of HTML over web sockets?

Because you can do things stateless HTML alone cannot do.

No one is trying to re-implement HTTP, or even remove it from the equation.

What people are trying to reimplement (or rather, replace) is the HTML + JSON:API + React + Redux mess. Websockets is a means to that end.

Re:The future of web software is HTML over WebSockets by wokwokwok on Thursday February 25, 2021 @11:22PM (#26271340)
Hm... great intentions, but you don’t seem to have actually answered any of the questions from the parent comment.

Unfortunately, great intentions alone won’t make this work; someone has to actually answer the hard questions about how it’s going to work too.

All the answers I’ve seen so far trying to answer them have been vague hand waving...

That doesn’t leave me with much confidence.

Re:The future of web software is HTML over WebSockets by coldtea on Friday February 26, 2021 @01:14AM (#26271818)
>Unfortunately, great intentions alone won’t make this work; someone has to actually answer the hard questions about how it’s going to work too.

People did better than that, they already built applications with this model.

Re:The future of web software is HTML over WebSockets by ricketycricket on Thursday February 25, 2021 @11:35PM (#26271397)
You are welcome to actually look at the code for any of these solutions.

Here is the documentation for Phoenix channel authentication (what Phoenix Live View is built upon): https://hexdocs.pm/phoenix/channels.html#using-token-authent...

Additionally, here is some documentation on the security considerations specific to Live View: https://hexdocs.pm/phoenix_live_view/security-model.html

Searching can probably find you more information.

Re:The future of web software is HTML over WebSockets by Graffur on Thursday February 25, 2021 @04:50PM (#26268791)
What you mean by sockets in "exciting until you realize the “boring old stateless World Wide Web” was built over decades of iteration using stateful sockets as the backbone".

I should probably already know this.

Re:The future of web software is HTML over WebSockets by keithwhor on Thursday February 25, 2021 @05:57PM (#26269418)
HTTP is a stateless protocol built on top of TCP network sockets [0] intended to standardize transfer of hypertext. It's the backbone of the WWW.

HTTP is quite literally "hypertext over sockets" so "HTML over websockets" is functionally equivalent... with a layer of abstraction added on top. If you build web software by sending HTML over websockets you're just reinventing what already exists; it's probably why it's never taken off. I think most developers realize within ~weeks to months of working on a "websocket-everything" framework that they're doing more work, not less.

[0] https://en.wikipedia.org/wiki/Network_socket

Re:The future of web software is HTML over WebSockets by coldtea on Friday February 26, 2021 @01:11AM (#26271803)
>- What if the remote server crashes through no fault of your own (AWS server rack catches fire)? How do you ensure a consistent reconnection that preserves application state?

Why would you? Nobody seems to ensure that with regular SPAs anyway...

Re:The future of web software is HTML over WebSockets by dnautics on Thursday February 25, 2021 @04:39PM (#26268672)
> The problem is that stateful connections suck and create artificial complexity when you don’t need them. Instead of managing the state of your app you’re now managing the state of your app and a connection to a remote server. HTTP is a stateless protocol on top of a stateful socket connection. It wasn’t designed this way by accident.

Seriously, try phoenix liveview if you haven't already. These problems of dealing with stateful connections over questionable tranport and managing them are what the Erlang vm were designed for, and phoenix was designed by rails core team members.

Re:The future of web software is HTML over WebSockets by cortesoft on Thursday February 25, 2021 @10:55PM (#26271207)
Isn’t the issue, though, how do you scale this out? HTTP app servers are great... you can add and remove them at will, based on load, and customers never know the difference, because it only takes a few seconds after not accepting new connections for the existing ones to drain.

If you instead have servers holding state, those servers become a lot less ephemeral.

In addition, HTTP has built in caching, which is a HUGE benefit for scale.

Re:The future of web software is HTML over WebSockets by ricketycricket on Thursday February 25, 2021 @11:28PM (#26271367)
dnautics isn't wrong. Even the issues you bring up are addressed by Erlang/OTP. Distributed Erlang with 10K nodes, hot code reload, etc.
Re:The future of web software is HTML over WebSockets by querulous on Thursday February 25, 2021 @11:39PM (#26271409)
the only people who think distributed erlang is good are people who have never done anything nontrivial with it
Re:The future of web software is HTML over WebSockets by hydroxyethane on Friday February 26, 2021 @02:36AM (#26272226)
Could you explain why that is to someone (me) has never done anything nontrivial with it? Thanks.
Re:The future of web software is HTML over WebSockets by querulous on Friday February 26, 2021 @03:49AM (#26272681)
i'd encourage everyone thinking about using it to go read the code (it's fairly approachable) but in short it just connects each node in the cluster to each other node in the cluster via a tcp connection and sends packets between them. there's almost nothing as far as protocol, queue management, congestion control or traffic management. it's discovery mechanism is just shipping lists of peers around. pretty much any competent programmer with networking experience could put together something comparable

it works okay in small clusters on reliable low latency networks but it's not a replacement for an actual network mesh

there have been attempts to fix it but none have really found adoption. i think this is the most notable: https://lasp-lang.readme.io/docs

Re:The future of web software is HTML over WebSockets by hydroxyethane on Friday February 26, 2021 @04:50AM (#26273078)
thanks for your answer so basically it relies on plain TCP and its reliability features. If you need something more sophisticated you gotta do it yourself within the application code (or using libs).
Re:The future of web software is HTML over WebSockets by dnautics on Friday February 26, 2021 @11:42AM (#26276679)
Elixir tends to have sophisticated libraries around what you really want that are plug and play with distributed erlang. (Phoenix pubsub/tracker/presence). Horde/swarm, etc.
Re:The future of web software is HTML over WebSockets by dnautics on Friday February 26, 2021 @02:04AM (#26272063)
I work on a system with an distributed erlang service mesh.
Re:The future of web software is HTML over WebSockets by shakow on Thursday February 25, 2021 @04:53PM (#26268820)
> Instead of managing the state of your app you’re now managing the state of your app and a connection to a remote server.

Wouldn't an intermediate layer such as e.g. Phoenix/LiveView (https://www.phoenixframework.org/) solve the problem?

Re:The future of web software is HTML over WebSockets by nickjj on Thursday February 25, 2021 @05:09PM (#26268961)
> Wouldn't an intermediate layer such as e.g. Phoenix/LiveView (https://www.phoenixframework.org/) solve the problem?

I don't think so but if I'm wrong please correct me.

For example, imagine this simple scenario: you load the comment page for this post on HackerNews

HackerNews renders an HTTP response to your browser and your browser renders the page based on that HTTP payload.

You can be sitting here on the page for 10 minutes reading comments and even if HackerNews randomly went down 20 times for 10 seconds each time during those 10 minutes you would never know because your browser has everything it needed to render the page when it loaded. It's a done deal. The request was made and the response was served.

But now let's say you use LiveView and you made this page an actual Live View. Let's also say you load all of the comments at once to keep the example the same.

Since there's a persistent websocket connection open at all times, in all 20 cases of HackerNews going down you're going to get a visual warning that the websocket connection was dropped. You also don't want to disable this visual warning because on slower devices it might take 2 seconds to load the page which is much different than an uncontrolled disconnect.

IMO this user experience is pretty bad. Why should users be concerned with the server's state after it has everything it needed to handle the request it asked for (loading the comment page). If they try to post a comment and the server is down then the user should see that error at the time of them making the comment (such as a custom 502 error page if the back-end is down).

The grandfather's comment of "it wasn't designed this way by accident" is spot on. The stateless web is a happy web. Sure you can sprinkle in websockets for progressive enhancements like broadcasting new content somewhere (which is awesome when done well), but websockets shouldn't be the basis for everything. HTTP has decades of very careful thought and optimizations around its protocol.

Re:The future of web software is HTML over WebSockets by ricketycricket on Thursday February 25, 2021 @11:52PM (#26271477)
The sensible response to that scenario would be: Why did you make HN a Live View? I don't think anyone is suggesting that you make anything a Live View that is more appropriate as plain HTML. If you wouldn't use React, you shouldn't use Live View.

I understand you needed an example, but a better comparison would be a heavy SPA with real-time interactivity. In that case, if your server is down your API calls will fail and you're going to have to handle the failure and let the user know something went wrong any way. If anything, Live View's built-in buffer and retry can actually provide a better user experience because the UI will automatically "catch up" when the client reconnects.

> You also don't want to disable this visual warning because on slower devices it might take 2 seconds to load the page which is much different than an uncontrolled disconnect.

Live View loads the entire initial page over HTTP, then mounts the Live View. Your slow device won't see any difference if the visual warning is disabled or not.

Re:The future of web software is HTML over WebSockets by nickjj on Friday February 26, 2021 @06:22AM (#26273652)
> The sensible response to that scenario would be: Why did you make HN a Live View? I don't think anyone is suggesting that you make anything a Live View that is more appropriate as plain HTML.

It's because the creator of Live View himself said he's not going to be using "dead views" anymore for sites that don't need offline capabilities or are clear cases where LV would fall apart. He's advocating for everyone to use LV instead of regular views even to serve HTML for most sites.

I can see the appeal too, Turbolinks did a great thing a few years ago by improving page load speeds by turning regular HTTP requests into ajax calls behind the scenes and then swapping the <body> of the page, all without having to write a single line of code beyond importing the JS library and without having to change anything on the back-end.

With LV's live_redirect you can get a similar effect. It's a much different implementation (way more changes are needed on the back-end) but the end result is similar'ish.

And if you had a site that benefits from speedy page transitions (aka pretty much every site) and you happen to have a few cases where using LV makes sense such as wanting to do real time validations or show a stream of something then it would make sense to want to go all-in and use LV to serve every page so that you don't need to bring in both Turbolinks and LV as dependencies and still benefit by having fast page transitions across your site.

Re:The future of web software is HTML over WebSockets by morelisp on Friday February 26, 2021 @02:18AM (#26272141)
> If you wouldn't use React, you shouldn't use Live View.

I have bad news for you about how often most web developers are using React.

Re:The future of web software is HTML over WebSockets by lostcolony on Thursday February 25, 2021 @05:29PM (#26269148)
If the connectivity state doesn't matter to the user, why would you show it?
Re:The future of web software is HTML over WebSockets by TheRealPomax on Thursday February 25, 2021 @05:33PM (#26269184)
This. No reason to say "the server's gone!" when your user's not doing anything in which that matters. Do notify them _before_ trying to execute on a task that requires the server to be up, but that's not the case that was getting described.
Re:The future of web software is HTML over WebSockets by nickjj on Thursday February 25, 2021 @05:41PM (#26269259)
> If the connectivity state doesn't matter to the user, why would you show it?

It's due to Live View triggering a visual indicator that the websocket connection isn't available.

It's a combination of CSS and JS. You can turn this off but if you turn it off then you have no way to show an indicator when you do care (such as transitioning between pages or submitting a form).

I don't think LV at the client level can be coded in such a way that it can tell the difference between the server dropping and the user's connection dropping due to their internet being spotty.

Re:The future of web software is HTML over WebSockets by lostcolony on Thursday February 25, 2021 @07:35PM (#26270220)
So just to your last point, no one can tell the difference between "you, the client, can no longer reach this particular server" and "this server no longer is up". You might be able to tell that it's the user's connection, rather than a netsplit somewhere, with some reasonable degree of confidence (ping the ISP, ping google, etc), but that's a lot of work, still just a percentage chance of being correct, for no real benefit.

To the rest...that's the point, it's just...CSS and JS. You can change it. You can show it or not, based on what the user is doing, or what view they have. Worst case, you can just hide it completely across everything, as you say, which is then no different from an SPA, except where functionality fails when you have no connectivity. Whether that leads to a better or worse user experience is dependent on the dev's handling of those failures.

Re:The future of web software is HTML over WebSockets by shakow on Thursday February 25, 2021 @05:41PM (#26269262)
> You also don't want to disable this visual warning because on slower devices it might take 2 seconds to load the page which is much different than an uncontrolled disconnect.

You can restrict the visual warning to the first load only, it would be pretty distracting otherwise.

Re:The future of web software is HTML over WebSockets by nickjj on Thursday February 25, 2021 @07:38PM (#26270239)
> You can restrict the visual warning to the first load only, it would be pretty distracting otherwise.

How would this work in practice while still showing it when you want it to be shown?

Re:The future of web software is HTML over WebSockets by njharman on Thursday February 25, 2021 @10:46PM (#26271169)
If your server is done 20 times in 10 min, replace your incompetent eng, ops, service provider.

A feature that protects from ridiculously unlikely problem is no feature. It is over engineering

Re:The future of web software is HTML over WebSockets by blendergeek on Thursday February 25, 2021 @11:52PM (#26271480)
> If your server is done 20 times in 10 min, replace your incompetent eng, ops, service provider.

You could have incompetent engineers or you could have bad internet. The user could be on a train that is going in and out of tunnels. Or the user could be in a house using WiFi and the microwave could be causing interference.

Re:The future of web software is HTML over WebSockets by fogihujy on Friday February 26, 2021 @12:22AM (#26271611)
"Replace the user". ;)
Re:The future of web software is HTML over WebSockets by Joeri on Thursday February 25, 2021 @05:07PM (#26268939)
Not only that. The basic problem is latency. We moved logic to the client to be able to update the screen without incurring the latency hit of a server roundtrip. Latency isn’t going down, thanks to physics, so it is going to keep making sense to run logic locally to improve apparent performance. Granted, you need data to render something useful and if an SPA does a data fetch on every click, it might as well be rendered server-side, but still, it is going to keep making sense to render on the device in many cases.
Re:The future of web software is HTML over WebSockets by TheRealPomax on Thursday February 25, 2021 @05:30PM (#26269162)
Note that a websocket round trip is vastly shorter than an http round trip, though. If your payloads are small, 500 consecutive websocket back and forths take orders of magnitude less time than the "traditional" high level url post/fetch becauses there's none of the overhead of an http round trip.
Re:The future of web software is HTML over WebSockets by Matthias247 on Thursday February 25, 2021 @06:26PM (#26269691)
A round trip is a round trip. Software can’t beat physics.

If you want to do requests in parallel, http 2 and 3 can do them just fine. If it’s sequential, you won’t see a huge difference between something on websockets and http/1.1.

The only thing you can save are a few header bytes. And it’s up to you how many headers you use

Re:The future of web software is HTML over WebSockets by hnedeotes on Friday February 26, 2021 @12:18AM (#26271590)
I'm not going to say web sockets are the silver bullet as I don't think it is, but the "only thing you can save are a few header bytes" is a bit reductionist.

If you have authentication then cookies have to be going out also and any other information that has to be kept in order to provide state over a stateless connection. You still need to handshake on each connection (maybe http2/3 bring this down a bit), and you also don't have bidirectional flow, so if you need something resembling client side "real-time" functionality you now have to implement pooling, or server side events.

The biggest issue is basically how to load balance/scale and that becomes a problem only given a scale that 98% (scientific) of the websites online won't ever experience.

Re:The future of web software is HTML over WebSockets by Matthias247 on Sunday February 28, 2021 @08:48PM (#26298903)
> You still need to handshake on each connection

You can just use one connection (same as websockets)

> and you also don't have bidirectional flow

Sure you have. Each request and response has a body, and HTTP bodies are indefinite streams of data. You can do everything in them you like (including running your custom protocol). That's e.g. how gRPC streaming works.

Re:The future of web software is HTML over WebSockets by hnedeotes on Tuesday March 02, 2021 @10:13AM (#26316105)
Sure, but doesn't that end up being more complex than web sockets to implement correctly?

And keeping one connection then we're in the same spot regarding the scaling issues as with web sockets right? Or does plain TCP/IP have better support for changing endpoints mid-flight, reconnections and etc?

Although if so I don't understand why there was even the need to come up with Websockets? I personally would love to see a simplification of technology all across OSes, web, etc, but probably there's too much out there to provide a reasonable migration path... It sometimes feels like those projects that you work on in the beginning and then you look at, some years down the line and say, this needs a refactoring with all I've learned in the meanwhile regarding what I'm doing and regarding my understanding of the domain space - but sometimes you can't do it, doing it might not go well or you'll end up in the same place afterwards.

Re:The future of web software is HTML over WebSockets by TheRealPomax on Friday February 26, 2021 @12:45PM (#26277530)
Why would software have to beat physics? HTTP communication and websocket communication uses completely different models.

And note that we're not talking about parallel request, those are not relevant to the "constant stream of small updates as the backend state updates" model described in the article, so let's not get side tracked, and talk about the actual stream of small fragment data in HTTP vs websockets.

Every HTTP connection (whether it's v1.1, v2, v3, or some even newer Google-flavoured "we came up with another one!" version) requires secure connection handshaking before any actual data may be sent. And if you're using any kind of session management, which you will be, now you're also spending time on cookie transmission before you get to payload transmission. And yes, there is the "Connection: Keep-Alive" header that can be set to allow more than one request per established connection, but any sane setup has that either on a small timeout (hundreds of ms at most), or on a low number of requests. You're still going to be establishing lots of connections, over and over, during the lifetime of the content at the client.

So, for many payloads a lengthy (compared to small payload transmission) HTTP connection negotiation has to happen. This is not the case for websockets, which by design are as if the "keep-alive" was set to "forever": they get initiated through a one-time HTTP call that contains an "upgrade this connection to a websocket" instruction header, after which we're done. This is now an open, persistent, bidirectional data socket.

Connection-wise, the amount of time required for HTTP vs. websocket is immense.

Secondly, let's not try to lend credence to an argument by hand waving the number of bytes in headers: the model discussed here concerns pushing small fragment updates to the client, in which headers constitute a significant part of the transmission. You can see this is modern sites that communicate small JSON fragments today where payloads like `{"error": false, "result": 12}` get dwarfed by the modern response headers, because yes "you control yoru headers" but you're not running your first server (in fact, you're almost certainly not running your own server at all, you paid a host): a response will contain not just the HTTP version and content type and length, but also the cache control value, the CSP and CORS headers, and almost certainly some extra stuff like the datetime, cookie expiration, x-frame-options, etc.

Using websockets makes an incredible difference in the model discussed in the article.

However, if you want to discuss the merits of the two completely different models, that's fair. Why would you even use the small-payloads push model? Who cares if the client has some state that "hopefully" mirrors the server? These are good questions, and unless you're writing a multi-user application with a web front-end, I genuinely don't see why the approach outlined in this article makes much sense.

Yeah, React kind of shat all over the web (and I say that as someone who quite likes React) because it was never designed with the purpose of generating web content. It was born as an interface library and never stopped being one. Its fault is being so damn easy to pick up which means that every site on the planet now uses React to build normal web pages and even do page routing, instead of having the devs write their code in React and then hitting the "and now generate that as static site with vanilla JS for the interactive bits" button. Because that button doesn't exist, instead it's esbuild (or previously, babel+webpack but thank god esbuild now exists so we don't have to use that anymore).

But that's a completely different discussion and really not related to how websockets are incredibly much better for the stateful server, thin client, many-small-updates push model.

Re:The future of web software is HTML over WebSockets by mbreese on Thursday February 25, 2021 @10:25PM (#26271077)
I see websockets as the endpoint for trying to fix two problems in HTTP 1.0 that has been simmering for over two decades.

For all of the stateless goodness that HTTP is, in order to have user-specific content, you need to know who you're talking to. The hack to fix this was cookies. Instead of using a traditional stateful protocol (which could have kept track of the logged in user), we had a stateless protocol where the user basically had to present credentials with each request (also, HTTP-AUTH).

The second issue was so problematic that it made it into HTTP 1.1 two years later. Because a stateless protocol was used, if you wanted to download say, a document and a linked image in the document, in HTTP 1.0, you needed to make two requests. Back when each web page was predominantly text with few graphics, this was okay. When we moved to more graphical (albeit table-based) layouts, this was horrible. So, HTTP 1.1 ushered in Connection: keep-alive to allow for the same connection to be used for multiple requests. You still had to make individual requests, but at least you didn't have the overhead of setting up multiple TCP connections.

HTTP isn't fundamentally broken, but it is a kludge. The most painful parts of HTTP were also the most "stateless" aspects. I agree I don't understand why HTML over Websockets is a (big) thing. It doesn't make much sense to me either. Then again, I was also doing dynamic updates (with javascript pulling in HTML, not XML) before A List Apart (hello again) coined the term AJAX.

But let's not just say that HTTP is a perfect stateless protocol. It isn't. It was never "designed this way" -- it was patched up with quick fixes during the late 90's that we've been stuck with ever since. Websockets is the latest attempt to fix this problem. HTTP/2 and /3 don't really do anything to address maintaining session state, but focus on making individual request more efficient (roughly). That still leaves us with the problem of Cookies. Websockets have their own issues (scaling for one), but adopting the approach mentioned in the article doesn't mean that you have to completely abandon the rest of HTTP. But, if I could avoid having every website yelling at me about using cookies, I'd happily adopt a Websocket architecture, if that's what it took.

Re:The future of web software is HTML over WebSockets by thwarted on Thursday February 25, 2021 @11:45PM (#26271440)
Why isn't an identifier included in each request ("a cookie") not a valid way to track state across requests? It's the solution that makes sense with an otherwise stateless interaction. With a persistent connection, you don't need to send that with each interaction, but the RIP:RPORT:LIP:LPORT tuple becomes the "cookie" that identifies the client or session.

> That still leaves us with the problem of Cookies. ... But, if I could avoid having every website yelling at me about using cookies, I'd happily adopt a Websocket architecture, if that's what it took.

This is a red herring. If "the problem with cookies" is that websites yell at you about using cookies, that's a legal issue with the requirement to notify users they are being tracked. This "problem" of being yelled at didn't exist before the legal requirement.

Moving the transport to websockets (layered on top of HTTP, layered on top of TCP) doesn't get rid of the legal requirement for notification or opt-out. It just buys some time until the law catches up and says that the state management you're using with websockets is also subject to tracking notification and opt-out.

Re:The future of web software is HTML over WebSockets by mbreese on Friday February 26, 2021 @09:27AM (#26275072)
> This is a red herring. ... that's a legal issue with the requirement to notify users they are being tracked

It’s not a red herring. And it’s not the website warnings that are the issue, it’s the tracking that they have to notify you about. If we didn’t have to allow cookies for basic interactions with websites (like a session cookie), then we wouldn’t need to allow tracking cookies at all. However, because we need to allow session cookies, other sites can then track us.

With a persistent connection/session, this wouldn’t be necessary.

But clearly, there are many other ways to tackle this problem. And the persistent socket connection also has issues. But after thinking about this, I think the company behind the current dominant browser may be a little conflicted about solving this issue. I’m hopeful about Firefox’s new approach.

Re:The future of web software is HTML over WebSockets by dynamite-ready on Friday February 26, 2021 @04:15AM (#26272834)
This is an aside, but to my mind, when necessary (when you're storing user data) devs should be transparent about how that data is stored. Websockets won't necessarily mean you avoid persisting state on the browser.

In fact, you'll probably find you'll need to store some tokens on the client, somehow, just to secure the client/server connection.

Re:The future of web software is HTML over WebSockets by Martinsos on Thursday February 25, 2021 @04:10PM (#26268380)
Do you have any preferences regarding a direction to simplify web development, remove some of the complexity introduced with client-server separation?
Re:The future of web software is HTML over WebSockets by fartcannon on Thursday February 25, 2021 @04:14PM (#26268429)
Use as little tech as you can. Write HTML, CSS and if you absolutely have to, javascript.
Re:The future of web software is HTML over WebSockets by snejad123 on Thursday February 25, 2021 @04:44PM (#26268734)
it's difficult to keep up with the design expectations of the modern web with just HTML and CSS.

It's possible but extremely difficult to create a "modern" experience with just html. Just like how we don't build houses with mud-bricks anymore even though it's easier than steel and wood.

Re:The future of web software is HTML over WebSockets by inopinatus on Thursday February 25, 2021 @05:52PM (#26269377)
On the contrary, I generally browse with JS disabled and there's a strong correlation between sites for which this is existentially problematic and sites whose content or utility are garbage.

I have a personal toolkit of components I call "you might not need Javascript". Dropdowns, slideovers, toggles, modals, tabs, accordions, autocomplete, lightboxes, all with nice transition animations, and all in pure server-rendered HTML+CSS. A lot of it is just semantic elements being used appropriately. How many developers use <datalist> or <summary>/<details>? or :target and :focus-within? In my experience, not enough. How about, using <details> in combination with a CSS [open] selector? The palette gets rich in combination.

Overall, no, it's not hard, but it does require one to study. A couple of times a year, I'll re-read through the HTML LS and CSS specifications. There's a lot in there to build from, and almost all of it has broad evergreen browser support. For the leading-edge stuff, "caniuse.com" remains an essential reference. I currently have my eye on the <dialog> element, high expectations there, works well already in Chrome; Firefox just has a couple of bugs to shake out, and it's experimental (but incomplete) in Safari.

All that said: a light dusting of JS can still provide progressive enhancement, but we can limit this to minor cosmetic improvements & optimizations, for browser compatibility, and where dynamic ARIA markup is necessary.

The motivation as to why I prefer this style is another matter, and it's do with product strategy, and in particular, not crystallizing your architecture in the front end (where it is brittle) but in the backend (where it is much faster to pivot and/or rapidly prototype/spike/redevelop, by proximity to business logic and persistence schema). These are understandings that've been long (and sometimes painful) in the learning, but they're pretty much universal.

Re:The future of web software is HTML over WebSockets by goalieca on Thursday February 25, 2021 @06:19PM (#26269631)
Survey monkey is completely broken without js. I did a survey this afternoon on it. Considering it looks like a few radio buttons and simple forms.. I just don’t understand.
Re:The future of web software is HTML over WebSockets by ivanb on Friday February 26, 2021 @04:24AM (#26272906)
> A couple of times a year, I'll re-read through the HTML LS and CSS specifications.

What is HTML LS?

Re:The future of web software is HTML over WebSockets by aembleton on Friday February 26, 2021 @07:03AM (#26273948)
Re:The future of web software is HTML over WebSockets by lmarcos on Thursday February 25, 2021 @05:12PM (#26268994)
How so? One of the most popular (if not the most) websites for developers out there is pretty much HTML + CSS. JavaScript is used, but minimally.

"Modern" experience is not necessarily the same as "good" experience. Good old server side rendered pages are fine; SPAs are being built just because "we can", not because they are actually needed (sure, in some cases,SPAs are needed, e.g., chat sites).

Re:The future of web software is HTML over WebSockets by IgorPartola on Thursday February 25, 2021 @05:27PM (#26269130)
Are you talking about Reddit, StackOverflow, or something else?

I have yet to see a proper web app (not a blog/collection of static pages, but something that does something complex like let you manage inventory, do payroll, do your taxes, monitor sensors in real time, interact with geographical maps, or edit documents) that is done without JavaScript and has even OK UX.

SPAs are great because of separation of concerns. Sever takes care of the data (storing it, syncing it, authenticating your access to it, serving it, sharing it). Client takes care of presentation. I build SPAs because they are better. Imagine if all the apps on your phone or computer were effectively HTML documents rendered on the server. Emacs over HTML/CSS? Minesweeper? World of Warcraft? Would that be an OK experience? Probably not because you don’t want to wait for a page load every time you do something in your Minesweeper game or check stock prices or whatever. Why should web apps be inferior?

When people complain about SPAs it’s because they don’t like web apps running in the same environment as their document-based content. I guess some people prefer the ActiveX/JavaApplet model, which to a degree I can understand. Slack is an application, not a website. But let’s not overlook the fact that implementing a Slack client with just HTML and CSS would be miserable to do and miserable to use.

Re:The future of web software is HTML over WebSockets by vagrantJin on Thursday February 25, 2021 @07:33PM (#26270206)
> Why should web apps be inferior?

Inferior compared to what?

I'm not going to call your statement nonsense but unless you have proof that SPAs make up the majority of the websites/web apps online today, I'm afraid I must disagree.

Frontend dev is a hot mess of garbage JS cobbled together to make a psuedo native experience.

> but something that does something complex like let you manage inventory, do payroll, do your taxes, monitor sensors in real time, interact with geographical maps, or edit documents) that is done without JavaScript and has even OK UX.

This is not what the web was built for. The same things you mention dismissively (server side Static pages) are the core and norm ,by and large, the vast majority of what constitutes "the web"

Good, lightweight native apps can do all the above without breaking a sweat, and you can have multiple native clients for things you care about. I don't always have an internet connection but I still want to type my documents. I fire up word. Not google docs. I need to do some serious data wrangling - I fire up excel not google sheets. Need to do some networking for my router, wireshark. Need to read an ebook - adobe acrobat. Need to write some shader code - Sublime text.

So the way it looks to me that SPAs are trinkets - not at all mission critical beyond loading cat pictures faster or bending the web backwards to do things it wasn't supposed to. Server side static pages rule the web.

Complexity is just a good way to justify a large paycheck.

Re:The future of web software is HTML over WebSockets by IgorPartola on Thursday February 25, 2021 @08:00PM (#26270389)
I’ll give you two counter arguments and if they don’t work I think our best bet is to agree to disagree. First, I think your premise that apps are not what the web was built for is flawed. Sure, this isn’t what the web was built for, same as the Internet wasn’t built for the web, and the phone and cable lines were built for the internet, and so on. The web had a vision that changed mid way. No we can either try to go backwards and give up a really important feature (forthcoming) or we can move forward and push past what is essentially a tooling problem. In other words, just because in the 1980s web apps could not be envisioned does not mean that they shouldn’t be envisioned today.

The second argument is that there isn’t a technology today that supersedes the web in one crucial feature: no installation required and updates are transparent. Various app stores are trying to solve this in a platform specific way but do you really want to live in a world where to publish an app you must include Apple and Google and Microsoft in your deploy path? You and I may be able to go to GitHub and download OpenStreetMaps code, then download all the data, install it all locally (most of the documentation last I checked was still in German BTW), and then use it to find directions to the nearest Starbucks. An average user will give up before spelling out “GitHub”. If you can point at any platform that lets me type in the name of an application and stat using it in under 1 second without installing anything whatsoever on my system, I will eat my hat.

That isn’t to say that we can’t have nice things. With time and effort you can create such a platform and get all OS vendors to support it and all the developers to move to it. But I will postulate that fixing the JS frontend mess will take at least an order of magnitude less effort. Therefore the web is where these types of applications will live.

Again I am not talking about things that are static. This isn’t about a blog. This is about whether a real application is better server-rendered or as an SPA and I argue that in 99% of cases an SPA will be a cleaner architecture AND provide better experience to the user. The fact that coding one up is annoying (arguable at best) is a temporary tooling problem, not a fundamental design flaw.

Re:The future of web software is HTML over WebSockets by vagrantJin on Friday February 26, 2021 @04:23AM (#26272894)
I'll use an analogy. We web developers are building a boat using a 1992 Toyota Hilux as the hull.

Top Gear proved it was well and truly possible. It's a popular mode of transport. It carries things. It has an engine and a mostly metal body.

It still isn't quite a boat

Web apps can walk and talk like native apps, but they aren't. Sure one off things like a Facebook or spotify or meme generators can rightfully be served from a web app - but applications for computing and getting work done?

Oh and don't forget about mobile devices - what amount of web apps do you prostulate people use there?

> SPA will be a cleaner architecture AND provide better experience to the user.

This. This is nonsense.

Re:The future of web software is HTML over WebSockets by IgorPartola on Friday February 26, 2021 @11:18AM (#26276360)
I won’t debate your analogy because I think it is flawed for reasons such as you can’t change the fundamental definitions of a car as easily as we can change web standards, as we have done over the past 30+ years.

I will point out that I routinely use Reddit on mobile Safari and it is most certainly a web app. Things like Twitter, Facebook, etc. are also apps, and while you can download a native version, for privacy reasons I prefer their web app counterparts as they are less able to spy on what the rest of my phone is doing.

I will also again point out that Google Maps is a better experience than downloading OpenStreetMaps and setting it up yourself. Even something like Slack and Discord and Google Docs are perfectly good experiences on desktop browsers and require no installation whatsoever. You aren’t really addressing the zero installation point at all and that’s at the crux of why web apps are a thing and their main draw. You quoted my conclusion and called it nonsense without any basis since you provided a straw man argument and didn’t address the main point at all.

Re:The future of web software is HTML over WebSockets by pseudalopex on Thursday February 25, 2021 @09:21PM (#26270797)
When people complain about SPAs it's because they're slower or less fit for the task than a collection of mostly static pages.
Re:The future of web software is HTML over WebSockets by IgorPartola on Thursday February 25, 2021 @11:21PM (#26271334)
You can build a poor UX with either technology. That does not to me condemn the technology itself. If a technology makes it easy to create a bad UX that may be grounds for condemning it. I have written horrible SPA code in my early career using nothing but straight up jQuery and yeah that can lead to bad UX. I like the way Vue does things and liked the way Angular 1 worked pretty OK. I don’t love React but don’t have anything against it. None of these inherently lead to a bad UX, IMO.
Re:The future of web software is HTML over WebSockets by didibus on Thursday February 25, 2021 @06:17PM (#26269607)
Not sure what is so hard about a client/server roundtrip?

The server side is being broken up into micro-services which makes all server a client/server roundtrip as well. Your DB was always running seperately making it a client/server roundtrip, etc.

Maybe I'm missing something, but what aspect of client/server is overly complex? And why is websocket (a client/server roundtrip mechanism) any easier?

Re:The future of web software is HTML over WebSockets by ric2b on Saturday March 06, 2021 @12:15PM (#26368849)
>The server side is being broken up into micro-services which makes all server a client/server roundtrip as well. Your DB was always running seperately making it a client/server roundtrip, etc.

The backend is likely all in the same building with a reliable and high-bandwith link between servers.

You can't compare that to a round-trip from the client to the backend.

Re:The future of web software is HTML over WebSockets by IgorPartola on Thursday February 25, 2021 @05:24PM (#26269103)
VueJS SPA + simple REST API will get you a really nice experience for most CRUD type apps. For the backend I like Django.
Re:The future of web software is HTML over WebSockets by cutler on Friday February 26, 2021 @12:37AM (#26271682)
PHP has its uses. Stateless request/response model with shared nothing can act as a kind of immutability. Facebook scaled for the first couple of years with just PHP 4 functions, arrays and templated HTML. The Ajax came later.
Re:The future of web software is HTML over WebSockets by egfx on Thursday February 25, 2021 @03:52PM (#26268145)
You sound like someone that gets it and after reading further it appears you have built an app in this space, and this makes sense. I have too and your right, the coolness of the realtime web is also it's achilles heel. It's not that the web wouldn't be better off realtime, it's just that there is unlikely to be in most cases a time when more than one person if any at all will consume a shared resource. And now you have to account for the most sensible case being the static state of the app where you are over-engineering the realtime features that are not really going to be used that often. In my app I had a a channel state (realtime) and a snapshot state (static). Only thing that made sense in the end was the static snapshot state for content consumption.

Here is a short demo of the product: https://www.youtube.com/watch?v=TwkgGBrK_tA

Re:The future of web software is HTML over WebSockets by rsj_hn on Thursday February 25, 2021 @10:31PM (#26271113)
All connections are stateful the moment any kind of volatile data is added. The question is how to manage that state.

Say you have a doctor that is associated to a group of patients and is allowed to update their patient's status. And if, while the doctor is filling something out for that patient, the patient changes doctors, then the current operation has to fail and the doctor needs to be notified of this change somehow.

So what do you do with the stale list of patients in the browser DOM?

Does the UI wait to see if the write fails, or does it increase reactivity by supporting a server push? And how do you tell the DOM to update the list of menu items so that that Patient X is removed from that list? What if half the doctor's patients have been removed? Does the UI wait for the doctor to try to make some change to all of them and one by one remove a patient or does it reload the full patient list? And if so, how often does the browser poll for the full the patient list -- during every operation involving a patient?

The server push reduces the amount of time wasted by the doctor filling out stuff for a patient that will be refused by the server anyway, and it avoids costly polling, reducing bandwidth. I get that it may not be worth it, it depends on how important reactivity and bandwidth are to the app, which is why videogame makers need to do it but people writing marketing pages don't.

Either way, you have a stateful connection as the set of patients available to that doctor is important connection state that can change at any time. So you are long past the idea of REST whenever you start building an interactive UI with data that must be synced from a remote server.

I am not a fan of the server push, but I feel that ship has sailed and people are adding in a lot more complexity for the sake of improved reactivity. My personal rule of thumb would be to always sacrifice reactivity for simplicity, but then this is why I don't build marketing pages.

Re:The future of web software is HTML over WebSockets by aembleton on Friday February 26, 2021 @07:02AM (#26273934)
> So what do you do with the stale list of patients in the browser DOM?

Write the front end in something like Vue. When you catch an error from an axios call, update your data model by calling the server for updates.

When the data model updates, Vue will automagically update the DOM used by the browser.

Re:The future of web software is HTML over WebSockets by rsj_hn on Friday February 26, 2021 @02:58PM (#26279147)
Right, but you can see how in some use cases it's important for the data to be relatively fresh, then you have to choose between polling and server push.
Re:The future of web software is HTML over WebSockets by tshaddox on Thursday February 25, 2021 @06:46PM (#26269849)
I agree that the good ole stateless HTTP protocol is great, but the thing is, as soon as your web page is simultaneously displaying content from two separate HTTP requests, your web page itself is maintaining state. That's very evident on complex single-page applications like an email, chat, or calendar app, but it's also true even if you load static HTML from a server then have a bit of client-side JavaScript that checks authentication status and shows the visitor's profile picture in the top bar if they're logged in. That's a pretty basic technique that web developers have been doing for probably 20 years, yet it already requires tooling and/or developer thought to manage what is now a stateful computing session.
Re:The future of web software is HTML over WebSockets by coldtea on Friday February 26, 2021 @01:10AM (#26271799)
>The problem is that stateful connections suck and create artificial complexity when you don’t need them. Instead of managing the state of your app you’re now managing the state of your app and a connection to a remote server. HTTP is a stateless protocol on top of a stateful socket connection. It wasn’t designed this way by accident.

Then again, it wasn't designed this way to build applications with, either. It was designed to serve documents (the HT in HTTP).

Re:The future of web software is HTML over WebSockets by networkimprov on Thursday February 25, 2021 @03:59PM (#26268244)
I built a localhost web app, where the app runs locally and displays its UI in one or more browser tabs. [1]

It uses websockets & JSON to connect the SPA UI (in Vue.js) to the app (in Go). That works well, and I can't imagine any advantages to generating HTML with Go, except perhaps less JS code :-)

[1] https://github.com/networkimprov/mnm-hammer

Re:The future of web software is HTML over WebSockets by mathgladiator on Friday February 26, 2021 @03:41AM (#26272639)
You're not being a jerk, but you are applying wisdom. The challenge is that if we don't have the courage to be foolish, then we will not make progress.

All the problems with a stateful connection are solvable, but we have yet to figure out the right way to teach the discipline of doing it right. It is an exceptionally expensive proposition to solve, so most people shouldn't solve it as they will be picking up a huge bill.

The challenge is that HTTP is fundamentally broken for stateful experiences, and people are trying to build that into everything these days. They want shit to update across machines, and polling is exceptionally easy at great cost.

Re:The future of web software is HTML over WebSockets by bennysonething on Thursday February 25, 2021 @04:40PM (#26268684)
Genuine question: is this what Microsoft blazor is?
Re:The future of web software is HTML over WebSockets by kevingadd on Thursday February 25, 2021 @04:41PM (#26268691)
Blazor has two modes, one is based on client-server round trips to talk with managed code on the server, the other runs everything on the client using WebAssembly
Re:The future of web software is HTML over WebSockets by cookiengineer on Thursday February 25, 2021 @10:29PM (#26271103)
Anybody remember GWT? [1]

Let's not go there again. It's the definition of worse than flash. And mostly for above described reasons.

Networking, Animation, Transitions, APIs, State of Data, State of Synchronization, Unpredictability and Unreliability of UI/UX States... all mixed together in a single socket.

Have fun debugging this blob of autogenerated code and transactions.

[1] www.gwtproject.org

Re:The future of web software is HTML over WebSockets by daotoad on Thursday February 25, 2021 @07:40PM (#26270256)
This seems like a more complicated SPFjs over websockets that is deeply wedded to a particular Ruby framework.

http://youtube.github.io/spfjs/

Re:The future of web software is HTML over WebSockets by brightball on Thursday February 25, 2021 @09:02PM (#26270705)
Except Phoenix LiveView has essentially removed the complexity.

Normally I’d agree with your take entirely and I don’t actually think it’s possible to avoid the complexity issues in non-BEAM languages...but Phoenix is absolutely doing it.

Re:The future of web software is HTML over WebSockets by the_gipsy on Thursday February 25, 2021 @03:26PM (#26267822)
Also I've seen request/reponse over websockets too many times.
Re:The future of web software is HTML over WebSockets by happyconcepts on Thursday February 25, 2021 @11:48PM (#26271462)
Just sayin' ... this time around ... a) the universe of gamers is larger and b) there's a larger base of phones which can be thought of as thin clients versus a full PC and c) node.js is widespread with Deno upcoming and d) multiplayer VR is closer to reality if it only need to compute one state at the server?

Multiplayer online experiences are also growing to include more than gaming, such as betting and gambling and zoom and trading crypto.

Are websockets and or browsers improving to handle this server centric shift?

Re:The future of web software is HTML over WebSockets by eeZah7Ux on Thursday February 25, 2021 @07:24PM (#26270138)
> HTTP is a stateless protocol on top of a stateful socket connection. It wasn’t designed this way by accident.

The complexity benefit of having stateless HTTP transactions is vastly offset by the statefulness of TCP, TLS states, HTTP "sessions", cookies, browser storage & so on.

HTTP is hardly "designed" and plenty of its aspects were accidental.

Re:The future of web software is HTML over WebSockets by jimmont on Thursday February 25, 2021 @08:11PM (#26270456)
the power drain alone, especially for mobile devices, makes this unrealistic