Better HN
topnewbestaskshowjobs
Log inSign up

andersmurphy

1,011 karma · joined Feb 22, 2019 (7y ago) · 496 submissions

https://andersmurphy.com
Submissions

comment 1y ago · link · parent

Thanks! There's definitely a discoverability problem. Most people just work along the edges. A billion is a long way to scroll! Honestly, I can't even find the stuff I've drawn in the middle.

At some point I should probably add some sort of minimap or something. Will be interesting to see the secret art people hide.

452.

Show HN: One Billion Checkboxes(checkboxes.andersmurphy.com ↗)

11 points · by andersmurphy · 1y ago · 15 comments

comment 1y ago · link · parent

So I actually do this (use compression to filter out bots) for my one million checkboxes Datastar demo[1]. It relies heavily on streaming the whole user view on every interaction. With brotli over SSE you can easily hit 200:1 compression ratios[2]. The problem is a malicious actor could request the stream uncompressed. As brotli is supported by 98% of browsers I don't push data to clients that don't support brotli compression. I've also found a lot of scrapers and bots don't support it so it works quite well.

[1] checkboxes demo https://checkboxes.andersmurphy.com

[2] article on brotli SSE https://andersmurphy.com/2025/04/15/why-you-should-use-brotl...

comment 1y ago · link · parent

Never had to use ping/pong with SSE. The reconnect is reliable. What you probably had happen was your proxy or server return a 4XX or 5XX and that cancels the retry. Don't do that and you'll be fine.

SSE works with normal load balancing the same as regular request/response. It's only stateful if you make your server stateful.

comment 1y ago · link · parent

This is the same with request response. You need to auth on each request (unless you use a cookie).

comment 1y ago · link · parent

This is a misinformed take. H2/H3 gives you 100+ connections. Even then you only need h2 from the proxy to the browser.

If you have to use H1 for some reason you can easily prune connections with the browser visibility api.

comment 1y ago · link · parent

This take that SSE is stateful is so strange. Server dies it reconnects to another server automatically (and no you don't need ping/pong). It's only stateful if you make it stateful. It works with load balancing the same as anything else.

comment 1y ago · link · parent

A story about how Brotli compression saved me from myself.

459.

Consider using brotli compression with SSE(andersmurphy.com ↗)

8 points · by andersmurphy · 1y ago · 1 comment

comment 1y ago · link · parent

The fact that you are saying they are trivial to solve means you probably need more visibility on your system. Reliable reconnect was the nightmare we saw regularly.

Unfortunately, I can't go into much detail on the mobile battery stuff, but I can give you some hints. If you do some reading on how antenna on phones work combined with websockets heartbeat ping/pong and you should get the idea.

comment 1y ago · link · parent

Tell me more!

comment 1y ago · link · parent

The original bit from the datastar website that was quoted was talking about polling.

comment 1y ago · link · parent

It's not just the performance, it's that there is a lot less ecosystem churn. I can run Clojure/Java code I wrote 10 years ago and it will still work.

comment 1y ago · link · parent

Yeah seems super fun. I've added it to my source reading list.

100% you can just do request response. What's nice is it can still be used to notify a user. Say they make a request that kicks off a background job, you can return UI that says the job has started, keep the connection open (cheap with v threads) and then when the job completes return the notification.

I honestly, wouldn't go down the CQRS road unless you are planning on adding multiplayer/coop/global notifications.

For the slow queries in a CQRS context I mostly solve that with caching. You can of course get fancy with datomiclike transaction queue/notification/listen fine grained pub/sub if that's your thing.

comment 1y ago · link · parent

Thank you for sharing. I was hoping you'd eventually publish an article on Yakread's ranking model, I remember you mentioning it tangentially in one of your talks.

Love how concise the code is.

comment 1y ago · link · parent

Please don't cargo cult CSP without understanding it.

unsafe-eval constrained to function constructors without inline scripts is only a concern if you are rendering user submitted HTML (most common case I see is markdown). Regardless of your CSP configuration you should be sanitizing that user submitted HTML anyway.

comment 1y ago · link · parent

So being on the front page of hacker news twice in 24 hours. The multiplayer game of life game is running on a 15.59$/month 4 core AMD 8GB ram shared VPS (hetzner) and only at about 30% load. That's with a Clojure backend running very naive code.

comment 1y ago · link · parent

Here's the thing datastar isn't really a framework in the traditional sense (ruby on rails), you can bring your own backend and use it in a variety of ways. I use it a push based CQRS style, but you just as easily do request/response, hell even polling if that's your thing.

comment 1y ago · link · parent

Cool. I didn't notice either. :)

With http2/3 the it's all multiplexed over the same connection, and as far as your server is concerned that up request/connection is very short lived.

Yeah mixed formats for compression is probably a use case (like you said once you commit with compression with SSE there's no switching during the connection). But, then you still need to configure compression yourself with websockets. The main compression advantage of SSE is it's not per message it's for the whole stream. The implementations of compression with websockets I've seen have mostly been per message compression which is much less of a win (I'd get around 6:1, maybe 10:1 with the game example not 200:1, and pay a much higher server/client CPU cost).

Websockets have similar issues with firewalls and TCP. So in my mind if I'm already dealing with that I might as well go UDP.

As for ordering, that's part of the problem that makes websockets messy (with reconnects etc). I prefer to build resilience into the system, so in the case of that demo I shared, if you disconnect/reconnect lose your connection you automatically get the latest view (there's no play back of events that needs to happen). SSE will automatically send up the last received event id up on reconnect (so you can play back missed events if you want, not my thing personally). I mainly use event ID as a hash of content, if the hash is the same don't send any data the client already has the latest state.

By design, the way I build things with CQRS. Up events never have to be ordered with down events. Think about a game loop, my down events are basically a render loop. They just return the latest state of the view.

If you want to order up events (rarely necessary). I can batch on the client to preserver order. I can use client time stamp/hash of the last event (if you want to get fancy), and the server orders and batches those events in sync with the loop, i.e everything you got in the last X time (like blockchains/trading systems). This is only for per client based ordering, no distributed client ordering otherwise you get into lamport clocks etc.

I've been burnt too many times by thinking websockets will solve the network/race conditions for me (and then failing spectacularly), so I'd rather build the system to handle disconnects rather than rely on ordering guarantees that sometimes break.

Again, though my experience has made me biased. This is just my take.

comment 1y ago · link · parent

Latency doesn't affect server update rate it affects time to first data. I can have a ping of 500ms and still get an update from a stock ticker every 5 milliseconds. They will arrive at 500 505 510 etc.

comment 1y ago · link · parent

Latency doesn't affect server update rate it affects time to first data.

comment 1y ago · link · parent

You can have microsecond updated, once the connection is established you can stream. Regardless of your latency.

Say your ping is 100 (units are irrelevant here). It will take you 100 before you see your first byte but if the server is sending updates down that connection you will have data at whatever rate the server can send data. Say the server sends every 10.

Then you will have updates on the client at 100 110 120 130 etc.

comment 1y ago · link · parent

Sounds like a django over abstraction problem. SSE is standard HTTP.

If laravel can do it django can.

comment 1y ago · link · parent

Thanks.

- Load balancing is easier because your connection is stateless. You don't have to connect to the same server when you reconnect. Your up traffic doesn't have to go to the same server as your down traffic. Websocket tend to come with a lot of connection context. With SSE you can easily kill nodes, and clients will reconnect to other nodes automatically.

- The compression is entirely optional. So when you don't need it don't use it. What's great about it though is it's built into the browser so you're not having to ship it to the client first.

- The connection limit of 6 is only applies to http1.1 not http2/3. If you are using SSE you'll want http2/3. But, generally you want http2/3 from your proxy/server to the browser anyway as it has a lot of performance/latency benefits (you'll want it for multiplexing your connection anyway).

- In my experience CPU/memory usage is lower than websockets. Obviously, some languages make them more ergonomic to use virtual/green threads (go, java, clojure). But, a decent async implementation can scale well too.

Honestly, and this is just an opinion, no I can't see when I would ever want to use websockets. Their reconnect mechanisms are just not reliable enough and their operational complexity isn't worth it. For me at least it's SSE or a proper gaming net code protocol over UDP. If your browser game works with websockets it will work with SSE.

comment 1y ago · link · parent

I'd argue the opposite.

I feel if anything Datastar is targeted ad veteran devs who are done with endless ecosystem churn, who want to use their favorite backend language and to make performant fullstack realtime collaborative apps.

If you haven't run the gauntlet you probably won't see the appeal.

comment 1y ago · link · parent

You don't need websockets SSE works fine for realtime collaborative apps.

Websockets sound great on paper. But, operationally they are a nightmare. I have had the misfortune of having to use them at scale (the author of Datastar had a similar experience). To list some of the challenges:

- firewalls and proxies, blocked ports

- unlimited connections non multiplexed (so bugs lead to ddos)

- load balancing nightmare

- no compression.

- no automatic handling of disconnect/reconnect.

- no cross site hijacking protection

- Worse tooling (you can inspect SSE in the browser).

- Nukes mobile battery because it hammers the duplex antenna.

You can fix some of these problems with websockets, but these fixes mostly boil down to sending more data... to send more data... to get you back to your own implementation of HTTP.

SSE on the other hand, by virtue of being regular HTTP, work out of the box with, headers, multiplexing, compression, disconnect/reconnect handling, h2/h3, etc.

If SSE is not performant enough for you then you should probably be rolling your own protocol on UDP rather than using websockets. Or wait until WebTransport is supported in Safari (any day now ).

Here's the article with a real time multiplayer Game of Life that's using SSE and compression for multiplayer.

https://example.andersmurphy.com

It's doing a lot of other dumb stuff explained a bit more here, but the point is you really really don't need websockets (and operationally you really don't want them):

https://andersmurphy.com/2025/04/07/clojure-realtime-collabo...

comment 1y ago · link · parent

That's the number of divs combined with the CSS transition animation on each cell. If I remove the animation on each cell it runs much better on lower end devices (looks a lot worse though). In general though older devices can't handle as many cells.

I'm sure you can write hyper specific hand tuned code for this example that will run better, but you'll lose all of the flexibility (and you have to load that hand tuned code first too). I could send down purely a string of data and have either an expression swap classes or wrap it in a web component (you can do both in Datastar). But, in short passing json and running your logic on the client adds up.

Like anything though test and measure.

comment 1y ago · link · parent

But, you can learn a lot doing dumb stuff. I learnt a lot about compression.

If you go to google chrome and throttle the site to 3G it will still run fine.

Rendering on the server like this will be faster for low end devices than rendering on the client (as the client doesn't have to run or simulate the game). It just gets raw HTML it has to render.

Effectively, the bulk of the work on the client will be done by the browser native rendering code and native compression code.

The other thing that might not be obvious. Is #brotli compression is not set to 11, it's set to 5 so similar CPU cost to gzip. But, the compression advantage comes from compressing the SSE stream. Tuning the shared window size cost memory on client and server but gives you a compression ratio of 150-250:1 (vs 30:1), at the cost of 263kb on both server on client (for context gzip has a fixed window of 32kb). This not only saves bandwidth and make the game run smoothly on 3G it also massively reduces CPU cost on both client and server. So it can run on lower end devices than a client heavy browser app.

So server driven web apps are better for low end devices. The same way you can watch YouTube on a low end phone but not play some games.

comment 1y ago · link · parent

It's deliberately naive. But brotli and a tuned compression window over SSE means it gets 150-250:1 compression ratio, combined with Datastar rendering speed and you can get away with it.

The reason it's naive is although you can use datastar to drive SVG, a canvas or even a game engine the minute you do people think you are doing magic game dev sorcery and dismiss your demo. I wanted to show that your average crud app with a bunch of divs is going to do just fine.

I break it down in this post.

https://andersmurphy.com/2025/04/07/clojure-realtime-collabo...

comment 1y ago · link · parent

So I've used Turbo 8 to make a multiplayer app using a non rails backend. It was a struggle, the docs are incomplete. I mostly pieced things together from what others have done and written about. Which, is ironic considering your point about having a massive community behind it. The nice thing about Turbo 8 is morph (it uses idiomorph like datastar). It's also got a pretty simple refresh model.

However, you quickly realise the limitation. You can even see this in the Turbo 8 demo (see this issue https://github.com/basecamp/turbo-8-morphing-demo/issues/9). You can try to fix this with `data-turbo-permanent` but you'll now run into another issue that you can't clear that field without resorting to JavaScript. Which, brings me to the next thing, I found I was still writing quite a bit of JavaScript with turbo. Like HTMX pushes you to use alpin.js/hypercript turbo pushes you to use Stimulus.js.

Turbo.js is not push based it's mostly polling based. Even when you push a refresh event, it pushes the client to re-fetch the data. Sure this is elegant in in that you re-use your regular handlers but it's a performance nightmare as you stampede your own server. It also prohibits you from doing render sharing between clients (which is what opens up some of the really cool stuff you can do with datastar).

I was using turbo.js with SSE so no complaints there. But, most turbo implementations use websockets (which if you have any experience with websockets is just a bad time: messages can be dropped, no auto reconnect, not regular http, proxy and firewalls can block it etc).

Finally, according to the docs Turbo Native doesn't let you use stream events (which is what gives you access to refresh and other multiplayer features).

I like turbo, I'd use it over react if I was using Rails. I use it for my static blog to make the navigation feel snappy (turbo drive). It gives you a lot without you having to do anything. But, the minute you start working on day 2 problems and you are not using rails the shine fades pretty quickly. There are 3 ways to do things, frames, streams and morph. None of them are enough to stop you having to import stimulus or alpine and honestly it's just a bit of a mess.

If you need help with turbo the best blogs posts are from (Radan Skoric https://radanskoric.com/archives/).

Specifically these:

https://radanskoric.com/articles/turbo-morphing-deep-dive-id...

https://radanskoric.com/articles/turbo-morphing-deep-dive

I think he's also got a book on turbo he's releasing soon (if you go with turbo it's probably worth getting).

Those posts helped me grok Torbo 8 morph and ultimately what sold me on datastar. Morph, signals and SSE is all you need.

As for mobile I'll just wrap it in a webview (as an X native mobile dev I can tell you it will lead to a lower maintenance app than native or react native).

TLDR: datastar solves all the problems I ran into with turbo and more. It's faster, smaller, simpler, more examples, better docs and easier.

1
1314151617