06:00 UTC Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Hacker Culture · Lobsters · · 49:53 runtime

Put State in the Right Place

Comments

In the wiki JavaScript Also namedApache
Transcript 7646 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

Let's get to it. Um,

so we have to start with the definition. Every good talk should be an an axiom is foundational statement or principle that is universally accepted as true without requiring proof. I love this because it's the mathematical version of trust me bro. Um, so this is coming from an a

wide ranging experience. I've had a lot of different interesting jobs working on interesting projects. And I don't always know what a good system is going to look like, but I can tell you right away when something's about to fail. Um, and that sometimes is valuable, but it's more to see make sure that for other people's projects, they don't see these same problems themselves. Um, the other thing is this comes from trench wisdom. Uh, a lot of these opinions are not going to be popular, especially on dev Twitter. I don't care. Um, and the other thing is, uh, we have so much to get through. The good thing is all this stuff, come talk to me afterwards. I will uh give you get into the details the metrics the heap allocations all that stuff but for now trust me bro um okay so my core axiom

the thing that I think is the root of all things that I run into uh that's completely avoidable is that state in the wrong place is the cause of most real world problems and that works all over the place but for me it's been a big issue in the web uh so hi I'm Delaney I've had a really weird career Um, I first started out in computer stuff doing video games and then getting into programming. Uh, through that I've done slot games doing both the art and the internal uh, networking messaging for these systems. So that I've kind of worked full stack in some degree. Uh, I've worked on real-time military systems uh, where you have to get the right information to the right people at the right time. Um, you can't be wrong and you have to be really fast. So it's not only just about being correct, but it's also being be correct down to the frame. uh also I worked at Cenadia uh on

nets for quite a while and I got to see large distributed problems and one thing I can say from working in that that space is that I don't think people realize uh this talks to me a lot about the web is that the web is a distributed problem and people don't seem to realize that they think it's this happy little path for the client and a happy little path for the server and everything's going to work out um it doesn't so uh be

aware also I was a circus performer for a long time and I ended up in Vegas doing shows and stuff. Uh, that's another story. We can have another talk about that. Sadly, I'm probably best known for making Data Star, a JavaScript framework by someone who doesn't really like JavaScript. Um, but you'll see why.

I think I might have actually solved this because I came from it from a very different perspective. And I think that's really helpful. So, for me, the browser's never been more capable and performant. It is amazing what a modern browser can do. they're doing so many really good things for you if you care about looking at what it does under the hood. Um, sadly the web has never felt heavier. It feels big and bloated and hard to use. And um, for example, like I think a lot of this comes down to that it's it's it didn't intend to be this way, but most are full stack JavaScript uh, projects. And I

went and tested this before the talk and a nex.js JS hello world just to get like your text on the screen is 500 megabytes

before you do anything like just hello world page 500 megabytes I want to

repeat hello world like this is crazy um absolutely massive um [laughter]

also I have to remember that like I've been doing this for you know quite a long time I've earned my gray hair and I forget that some people have their careers started after leftpad. Like leftpad [laughter] was a thing that happened in the JavaScript world where like sites went down because of a feature that wasn't in ESX. This is crazy. Um the thing is

what's weird too is you have these huge dependencies in this huge situation and it's not like oh I have something that I can rely on. I have this you know something that's heavyweight but now I can rely on it. If you're a Nex.js developer or a speltkit developer or one of these other projects, that's what you are. You It's not like you're a JavaScript developer. You live in these ecosystems and they don't really talk to each other. Um there are some projects like Tanstack that try to get around this, but it it's not really uh what I would consider the right way to do things. So out of all this, all of this beautiful sets of things that you're depending on, the one thing you get out of this is a lot of CVEes. Um, the thing is I actually just went through the ones that I I thought these to me these are all cell phones. Like this is not adding new features to the browsers. It's not extending it to do things that it can already wasn't doing. This is things that were completely avoidable. And some of these are critical. And if you're not from the web, you're probably like, "The web sucks." Like it's just full. This is all you think about, right? Um, but most of this has nothing to do with the web.

This has to do with this ecosystem that's built up over time gradually. Um, not on purpose. And trust me, I get why this is. I I really do because back when this first started, when single page applications started coming into in vogue, um the the

the servers were always built with one request was one thread. So if you look at the way Apache was built or Glassfish or any of the other things, this is this did not scale. It was not built to do async uh and KQ and all the other ways that you build asynchronous processes nowadays. Um, and when you saw someone's example, they would have like maps or spreadsheets or anything interesting. It was always done on the client side in the browser, right? That's how you could do it. And so the problem is you had the servers didn't really support things and then the client started doing these heavyweight things and it just slowly went down this path. Um, the other thing is that once once it got some headway, everyone started doing it this way. Um, and like why would you not do it that way? Everyone else already is. Um, the thing that I ran into is I don't see myself as a JavaScript developer, but I love the web for like the sandbox deployment things. Um, thing like in the military, it's hard to get a uh executable to be signed off on. It's a whole huge process. But you can have a browser and basically send content immediately and have it sandbox. Like that's a beautiful thing. But when I go and look at all these different frame, these are just the JavaScript framework of the week. When you hear that thing, that that's literally like you can test all these things. The irony with this set of tests that you can do of benchmarks, none of this none of these tests actually test from the server all the way to the client and the entire process that it goes through. Like they're all making these weird synthetic benchmarks and stuff of testing who's better at like being the worst option.

Um, it's really weird. So the thing is I

for a long time I was busy. Everyone's busy. I was blackpilled. Like I was like h it's good enough. like I don't know this is a this is a bad situation. Um and it's really bad. So what I'm going to talk about here is basically I think this applies to everything outside the web but right now the web is definitely this is 100% the problem. Um and there's three ways where things can fail that we can try to we can fix this today. It's not just this is a problem. This is can be fixed. So the things I want to talk about today are optim optimistic updates are a lie. uh custom code is imperative

generally and uh polling leads to stale state. So my core philosophy of building systems from coming from gamedev and doing all kinds of interesting things is a purpose-built engine plus declarative data is really where you want to be. If you have those that combination of highle data data oriented style things and you have a purpose-built engine that knows how to deal with that data that's where real magic can come. There's this guy called uh Dr. Hip. He did this thing called SQLite. I don't know if you guys have heard of it. Um but this is an example of declarative things that to me is magical because as a user you say create index or create unique index and you're not telling him

how to invalidate the his cache or like

to rebalance the B tree or change the way the pages work. You're saying I need to index because I know the intent of what needs to be in place at this time. The simplicity of that is beautiful because you as a user are thinking these higher order ideas and you're allowing him all the flexibility to do the things he needs to do under the hood. To me, that's that's really where we want to be is either working at the high level or the low level here. So, if you're doing the web stuff, the web is already browsers are already a purpose-built engine for sending hyperdia to the to the client. It is literally a hypermedia client. That's what it is. So why do we stop using it that way? Because the thing is a browser out of the box does all this stuff sandbox for you in a beautiful way. It has features like doing stuff for actual devices. I can tell you you know setting up a GL context and like what you have to do per thing. There's a lot of work there. You just get that in like five lines or three lines of code. It's it's pretty amazing what's already there. And the nice part is so we have a purpose-built engine and for me declarative code is mostly there because HTML and CSS are already declarative. You're not telling it what pixels to go on screen. You're not telling it how to deal with flex boxes. It's right there. You're saying this is my intent. Please render it. And the thing is it used to suck. It's gotten better. And the thing is now you can make things that actually work in all browsers in a proper way. Like the specs have gotten really good in the last few years. So Carson Gross who's

here has said JavaScript has one unbelievable feature. It's in the browser. Sadly, we're kind of left with JavaScript. That's kind of the the uh the ugly duckling in this situation. Um we can't get rid of the duck in this situation. So, what I try to do with this thing that I built called data star is I try to make the JavaScript part just a little bit more declarative. And that to me really opens up the door to how you interact with the web. So there is something that's already built into the browser and it's native in all the all of them called data star. It's actually called custom data attributes. The problem is I named it data star and it's data star attributes.

So it sounds like it's something that is some magical thing but it's something that's literally built into the browser. So I want that's where you're supposed to put code that you care about that's custom. Um and it ends up being just a string string. We'll get into it. But the idea is all your code goes in there.

The the good thing about the browser, it's very lenient in what kind of stuff you can put into the browser. So, you can put invalid attributes and it'll try to deal with them. But that's the unhappy path. Like, if you stay within the spec, you're allowing the browser uh vendor developers to actually make fast

paths and do things in an efficient way. So, I wanted to stay within the spec and live within, you know, how they've built things for us. So, like we can fix this with the tools they've already given us. So people talk about what data star is. To me, it's only two things. I want to parse those attributes easily. I want to add reactive expressions which are missing from JavaScript. And

that's it. That's literally the part that I care about. I want to just fix those two things to make them more declarative. And that's it. So that right now is around 4 kilobytes, not 500 megabytes, 4 kilobytes because that shouldn't be that hard to do. Um, the cool part is TC39 is this thing to bring uh signals into the browser. Once that happens, this is going to get about half the size. So, that's a good thing. It It's much smaller. The nice part is I built it like you would build a like kind of like an ECS game engine system so that everything else from here on out is a plugin. So, you can pick and choose however you want to build your systems once you have this declarative part in place. Um, what I found was when I first started the data star website, it literally was like, "Here's the three plugins that I use. Here's how you write plugins. Good luck." Um, yolo. Uh, but

over time, there's certain patterns that came up like people were asking for these things constantly. So, the thing is, why did I why did I have this problem where I'm like, I need to unblock pill myself. And so I'm working on something that's a a what I call a data engine which basically is taking event buses and data sets and open ontologies and trying to bring them all together. And the problem with that is that in that that uh universe I'm trying to build everything is a stream literally everything. And the web UIs of today aren't really built to do that. It's and I'm talking I want to be able to show stuff in microscond timings and that's just not something that's normal um apparently. But for me per performance really does matter. I'm looking just like you would look at at the low level. I think we can do really interesting things at the high level if we do care about our L1 caches, our heap allocations, all those kinds of things.

So for me, the act shave was I want to make the u the web UI honest and we'll get into what I mean by that in a second. I want to remove framework ceremony. I don't want it to be I don't want to be a data star developer. I don't want to be a Nex.js developer. I just want to like use the web and target it just like I would target WebGL. Like I'm not a WebGL developer or DirectX developer. a guy that's targeting that for what I'm building at this time. Um, and the other thing is a lot of the things that I have to do with streaming and doing compression and all these things in my my data engine, it's the same problem in the web. So, if I can solve it for data star and help everyone else, I can actually solve my problems at the same time. So, for me, the things that are really important is facts near the authority, which means every piece of data in your system, every event, everything has a source of truth. So, you need to be aware of where that source of truth is. And I think people get into a lot of headaches when they don't actually follow that. They try to wrap it or put it somewhere else. Um, rendering near perception just means that like wait till the last second to either create the pixels or create data.

Leave it to the engine to actually do that as much as possible. Um, and intent near the user. We'll go into that kind of comes down to uh don't lie, but also don't tell people like people when they click a button, they're not saying I'm buying this thing. They're saying I'm trying to buy this thing. And that little mental shift is really simple, but it's not the way that most devel web development works today. So, it's been about 3 years since I did the the first commits of this stuff. And the nice part is v1 is done. Like, it's out. It's working. And unless the browser stops backwards compat compatibility, I don't see really any reason to for that to change. And because the core idea is just those two ideas, I think it's really simple. Um, the nice part is we set up a 501c3. Uh, we actually put all the code into that.

We're um, stewards of the project, but we don't own any of the code. So, it's not like it can go away. No one can take it from you. Uh, which is a good thing. And for me, this is a solved problem. I can actually get back to the interesting problems. And targeting the web is no longer an issue for me or our our users. So, I have to give you a little whirlwind tour of what data star is before I can show you why we solve it. So, this is standard HTML. like this is nothing interesting. So you can take your data- key fu and what happens is in

the uh JavaScript that's accessible through the element data set key as a camel case and then the foo value. So it's just a map of string to string. That's what you get. That's all we get as a data star a custom data attribute. Okay. What can we do with this first principles? So let's just we're going to just look at the key part of the side of the the the equation right now. So I can name something plug-in. Okay, that's some value. Well, colon is technically valid um to the spec. So now I can break it up. So I have the plug-in name and then I have a key that I can work with. Okay, that's interesting. Now underscore not valid for reasons, but underscore valid or underscore modifier that's valid. So I can have a modifier plus some argument. Okay. So, if we take the the full solution here, is this pretty? No.

Like, but it's what we can do and still be within the spec, right? We can take this, parse it out, we can turn this into something that a plug-in can hook into and have life cycles and all this stuff. So, this is still valid uh JavaScript or it's valid HTML in fact. So, that's the key side. So, what is the value? What are we trying to do here? And a lot of times we as developers think in functional like or imperative code here of like this is the thing I need to do. But the real value for both users of things is something that looks more like a spreadsheet. Because the reason why this is valuable is because the data of what the functions are is part of the cell itself. Like you're defining a relationship when you're doing a spreadsheet, not defining what the code's going to do. So you're defining the higher order idea. You're not saying what the dependency graph is and how these things are going to update. you're just saying this is the relationship I want to have and that's why half of business just runs on someone's Excel sheet on someone's laptop right um so of course this doesn't seem interesting but the fact is like when you change this code you know using Excel or something that these things are going to update so having something that's reactive and declarative is really valuable so

now we're going to take we're going to look at this value now look at this side we already kind of talked about what the key is just imagine what this code does here we're creating a signal which is a reactive expression called count. We're going to take that count and since reactive expressions don't exist in JavaScript, we use the dollar sign. So the dollar sign says this thing whenever this thing changes, the rest of this plugin is going to change or get run again. So in this case, data on click is saying when that click when this gets clicked, set the count increment at one.

That's all it's doing. And in this case, we're using that uh count when it says data text to basically replace the contents of the page. not it's very clear that that's all that's happening here. Same thing with here. We can actually affect attributes that are already built into the brows or into the element. So here we're just saying disable if the count equals zero. Okay, so we're setting up the relationship. We're setting up what our intent is. And here we're actually saying I'm creating a new computed thing that's a total that's going to work when you map reduce blah blah blah. It's just JavaScript, but we're saying when this subtotal changes now we have a new value called totals that's going to update too. Under the hood, we have like the world's fastest signal processor and how we do it. That part doesn't really matter as much as we've done the efficient thing. So, you just define your relationships. And I think that's a really beautiful and pretty cool thing.

And the nice part is if you say, "Oh, I want to click." The at sign is just saying that this is an action. It means that we've sandbox this function. It's built into data star. So, you can see this is something that's not built in the browser. You can look right away what data star is giving me. Otherwise, it's just regular HTML. There's nothing special going on here. And same thing is like you have a click and now we added a modifier saying, "Hey, we want to debounce this thing." And then we use double click. We didn't like make double click. Double click exists in the browser. Like we don't need to wrap it.

It's it's right there. Like just learn it. So half of learning data star is learning what's already in the browser, right? So we're not wrapping things. So in that case, everything is a plug-in. So when you do the thing, even though we've broken it down where for me the core is a 4 kilobyte thing. If you include all this the plugins that we do in the the default build, it's under 12 kilobytes for the whole thing. Onetime cost. You add this from one CDN thing and you're done. And this does 95% of all um websites can be done with just these plugins, which I think is pretty neat. Um but let's say that there's something you don't want. You can just take one of these things out. But the thing we're probably most most well known, so for me, data star is just making reactivity in the browser. But one of the plugins that we're really well known for is these ones around SSE um and how we deal with talking to the back end. So let's get into what what that why I'm such a big fan of SSSE and why I think it's really a pivotal thing when people think about talking to the browser. Uh and we're kind of well known for doing real-time stuff, but for me that's it's the exact same thing as a CRUD app to real time is the exact same solution.

And the reason why that is is there's something called SSSE which is server send events but it's just a response type. It's not like a new it's not like a websocket. It's not anything like that. It's just a response type. And instead of sending down text HTML, you're sending down text event stream. And then you have this little format where you say, "Hey, I have an event. I have some data and I have two new lines. Congratulations. You guys now know SSE." Like that's all it is. And the cool part is like there's a little bit of a syntax that data star has specific for what it needs, right? But there's one for patch elements. There's one where you want to just patch the signals where you just send down a merge patch. Um again in not a format that we came up with. We using a standard called JSON merge patch. And that's it. Like that's what you need to actually uh interact with data star from the back end. I think that's pretty cool. Um the one problem with the built into the browser they have something called event source. Um, and it only

handles git. So when you do this SSC, it only handles git. And if you uh lose connection, it automatically reconnects for you. The the problem is the way they do that's pretty naive. So we end up in that in that 12 kilobytes in that in those plugins. We end up making it so it works with any method. It does act enough back off retry limits. If you change your tab, it automatically closes it and then if you change back, it automatically opens up. All these things are setable and configurable, but the defaults I think are really good, especially for caring about people's battery life and mobile and all that stuff, especially over 3G networks. And the nice part, it's still fetch. We do the minimal amount to basically interact with what's already built into the browser in the C and C++ layer. So all this stuff is just setting up the proper things to just do fetch. It's there's nothing special going on here. Um, so the cool part is that I showed you two like the two little things. There's one called read signals that basically saying I'm sending stuff from the client up to the server. There's one called patch elements which I already showed you a quick example of. And there's patch signals. And I'd say 95% of your time for most things you're just patching down what you want the page to look like. Under the hood, we're doing morphing. We're making things really fast and efficient. But you just say I want my page to look like this. And you send it down from any language. And when I say any language, I really mean that because because there's only three functions. We have SDKs for all these languages. And it's like a side project for us. Like this is not a big deal because there's literally three functions that you have to implement to actually have an SDK for that plugin. Uh people talk about DSR needing an SDK.

Really, it's the SSC part that needs an SDK if you want to do this. But again, it's just text, guys. Like it's not that hard. And there are times when having an SDK doesn't exactly make sense. Did I actually keep it up here? Did someone Oh, guess it's gone. Um, so

I had a little $5 uh ESP32 device that I

grabbed and said, "Hey, someone was saying, I wonder if I could use this for making UIs for my uh embedded device." So, I grabbed the $5 ESP32 and within an hour I had using their ESPT uh libraries for HTTP, had a full data store real-time streaming thing working on a $5 device. Um, that's to me pretty cool

because I'd never played with it and it was not a big deal. And why isn't that the way we think of the thing? Like I don't want to be a developer that is a Nex.js developer or a SPA developer. I want to be someone that can look at a target and say I want to target the web from that device because it has Wi-Fi. So part of that comes from I'm just we're just doing plain HTTP. It's specifically built to work with low power. People talk like why do you care so much about performance and stuff? is because I want to be able to do stuff like this and most of the tools that are out there just can't and that's that makes me sad.

The other thing is that because of the way that we do exponential back off and retries and build things, it works really well in like 3G networks. And I think a lot of times when developers are building things for the web, they forget to put on throttling. They forget to put on 3G. They forget to see what it looks like for people coming in and out of tunnels and all that stuff. Because if you have the source of truth is your server, you have to deal with it as if it's a distributed problem. And I think most people are just forgetting that part or just ignoring it. And I think that's that's a broken system we're in right now. Um, okay. So that was data star. That's like kind of the part like whirlwind tour. Like how do we solve these problems? How do you stop lying to your user? So there's this thing called optimistic updates. It was kind of covered uh before in a slightly different way. And this is pretending that things are working when they're not. And whenever I bring up optimistic updates, people say that's how games work. They're not correct. They are wrong. There's this thing called uh net code with roll back, which is how some things like fighting games can basically feel like they're really fast even though you're over a network. And what happens is it actually tries to predict what you're doing and then if it makes a mistake with its prediction, it'll go back and work. The problem with that is that it doesn't uh it only works if you have a fully deterministic game loop. So you have to have a perfect system and perfect state and then be able to replay the events. Um so this works great for certain kinds of games. Um, but the problem is this doesn't match web semantics at all. This is not how the web works and how things were with forms and payments and especially things that I deal with like medical records, legal things, things in the military where you have to know that when I said I'm going to do something, you did it. So, we're going to say uh in this case, we're trying to buy a ticket to this cool conference called software should work.

Every time you see that flashing, we are lying to the user. Okay, this is how most systems work today. You click the button. You made a made a claim. Most systems will actually say ticket confirmed right away or they'll set a checkbox saying got it. Then it goes off to the server. You're still lying to the user about having this ticket. It says, "Oh, I'm rejecting it." You're still lying to the user. And when you finally get the packets down, okay, now we're going to roll back. Now most systems try like when you see people do this with a ticket system hopefully they're not doing this but it problem is it happens in every single stage of web development and in web frameworks that you're like oh I don't trust this or I'm refreshing the page or I'm doing something that is counterintuitive is because people are constantly lying to you about where the state is and what's going on. So instead of optimistic updates, notice five steps, we're going to do something I call instant intent. And it's seems pretty similar, but what we're going to do is we're going to do that same by the ticket. And when that happens, since we have reactive signals on the page, we can affect the the button that we were talking to, but we can also disable the rest of the page. Like those same data attributes say disabled. Well, I can do that to the different areas. I can have something show that says, "Oh, hey, I'm reserving the seat." I can do that instantaneously, right, in the same frame. knock that out. But then on the server, I'm going off and doing my thing. I could send updates back down saying, "Hey, this takes a little time."

I could do that right away. Or in this case, I can just send that directly down and say, "Sat unavailable." We never had to letter our user. We never had to make it complicated. In fact, the other way is more complicated, but yet that's become the norm. I don't understand this. Like it's simpler. If you know where the state is, then update the state. If the state is I my intent is to buy this ticket update immediately in this in the in the client that's not a server action but the response is

okay that's all I'll talk about custom code is imperative um this is something that's like when you on our website we have a old school starfield uh thing on our on our page um the thing is to do this in the browser it's pretty simple you have this canvas element and you're just doing imperative code that's fine great the thing is is that that to me is not very powerful because you're you're defining what this is, but there's something that's already built in that allows you to write custom uh elements for the page and it's called web components. Um, and the the nice part about those is that you can literally take that isolate that state deal with the and expose properties and now you just have this nice star field thing.

You're like, well, okay, what's the big deal there? The cool thing about that is now I can drive that with stuff that's going on that I'm in control of, right? Um, so I can do it from the outside. So the implementation only cares about speed but you can drive it from the outside and in this case let's see please work please work. So yes so I actually am driving this with on the on the big screen. So the nice part is that when you're writing your your element you're caring about where the center is and how you're rendering and all that stuff but you don't care how if it's driven by mouse movements and all this thing.

you're decoupling those ideas and it makes it so nice to make cool little pieces like that. And the other part that's cool about it is now we have this thing that is available to every developer. You're not a like Nex.js guy to do that. You can use that element from Zeg or Odin or Rock or any of these

Billy sorry um any of these things and you're able to to do stuff right away. The problem is is that the current zeitgeist is Ryan Carnito is a well-known person. He built solid JS and he talks about all the different things and one of the things he says is web components are not the future. And to some degree I think he's right but for the wrong reasons. I think that web components are not the future for single page applications. Like you've already made all these bad decisions. You've already wrapped this thing. You've already made this 500 meg thing. Trying to fix it at that layer is like you're already broken. It's not going to work.

So yeah, it's adding more steps for them and they're not getting any of the value out of it. But if we build things in a different way and make it work so that everyone's a full stack developer, then I just think he's wrong because we get reusability in anything in a spec compliant way. And also I think the the major issue is um I've had a lot of disagreements about with people that I really kind comes down to most SPA developers really uh don't decouple element state from their application state. um and takes just a little bit more work to do that correctly and it's not that bad. So last problem that I

think uh can be solved is polling leads to stale state and in this case so uh

let's say this conference gets big. I'm talking we're selling out beyond Taylor Swift like she has to call us, right? So everyone's on board with this with this with Isaac. So um the thing is if you a lot of the times where you get into situations where something works and works fine and then all of a sudden you don't realize oh no this is a logarithmic thing mis was flat enough for long enough right um and the problem is I've dealt with situations where like people would say oh yeah I've tested my framework and I'm like well how many connections can it handle and they say like 10 and I'm like well I've tested out to like 30,000 and it's working. So, I care more about like the long tail of like when you get into production, when you get into things that matter, how's it going to act in those situations? And I've just found that most frameworks just don't care about this. Um, so the

other thing we want to do is not only be performant, but we want to make sure everyone's on the same playing field. So, let's say there's things where people are having the scalper situation. We want to avoid that. Is it possible to actually avoid? Yes. Um, so the problem

with polling is everyone's on their own timer and it's usually coming from the client. Clients usually say, "Hey, I want to update every 5 seconds or something like that." And as your system gets f more and more stuff is happening in your system, you this gets slower and slower and the actual state is always out of state. As you get more successful, you get more out of state and that's really sucks. like it sucks so bad when you get when you get successful and then you're like oh we have fail whales everywhere right um this can be avoided and in this case what I'm trying to show is that on the server I'm deciding to do a throttled update to the back end so I'm doing all kinds of internal processing but I'm going to throttle so that every 200 milliseconds I'm sending down the same thing to everyone else and the reason why that's interesting is that everyone is able to get the exact same thing at the exact same time. Some of this comes down to trust me bro of how this works but this does work in production. And the other thing that's interesting is that without changing any of your code, without changing how your templates work, without changes like your core mechanics of your things works, you on the back end can decide I actually have an SLA that says the box office has to be within 200 milliseconds, but I can slow things down if we get mass traffic from some other thing. So without changing your code, you can actually do dynamic uh updates and do and all this comes from is just putting back pressure in the right place. And if you only had an update every 10 minutes, then you just update it. And people think, "Oh, well, I'm opening these connections. I'm doing all this stuff." It ironically is actually less power on like a 3G device

to have a readonly open connection than to be opening and closing for polling. So keeping that open is not the thing. Again, some of this comes down to trust me, but do the measurements yourself and you'll be shocked at the difference. So there's a QR code. We can play this later if you want, but there's this example that someone wrote uh that is basically the game of life. And the the fun part about it is it's he does it as a meme against me because it's the worst version of this possible. And what I mean by that is it's literally each one of those grids is a div like individually CSS style div. It's so I call it a rendering demo like a stress test because it's the worst idea. But the neat part is he's doing it five times a second and it's on his blog server. So the interesting thing about that is that his blog server has been the top of hacker news with this thing multiple times and it's never gone down.

And the thing is it's impossible to get out of state with it and it was written in 300 lines of closure. So it's not even in a uh really fast like crazy fast language but it's good enough to be at the top of hacker news and never go down ever. So if it's good enough to do 2500 things five times a second it's probably okay for your normal crud app. Um, and the cool part is because basically what we tend to tell people to do, like you can send down individual targeted things, but we actually can send out entire pages of things. So he's sending down when he's doing that, he's actually sending down 2500 divs five times. Like it's not like doing individual updates.

He's sending all of it. And the neat part is we use brley and zstandard compression, window compression. And because most of that's going to be similar, it actually can keep track of that stuff. So instead of doing polling where you if you do Z standard you get like six to1 it's like over 300 to1 compression ratios. So you can just logically think about how you want your app to look like and we use the browser as our VDOM like we use the compression ratios to actually build those things in in a fast and efficient way. So the thing is you just send down the page as you want it from any language and let us deal with it and it's very fast and efficient.

And the cool thing is whether you're making a CRUD app or you're making this real-time thing, it's literally the same amount of code. You get collaboration for free. And I really do think like a web 4.0 thing is about opening the ideas of collaboration. And for me, the difference between a CRUD app to a real- time dynamic system that's live is the exact same code. There's no difference in the code. It's not harder. It's not more complicated. It's the same thing. So why aren't we doing that? So there has to be a cost to this, right? Like I get it. like I I'm selling you on like the web has solved like what what everyone's wrong. Um they are.

The nice part is it's been out long enough that there's been people like I've been using it heavily. I've been using it uh a lot and it's great, but we have enough of a uh following now that there are people that have actually taken projects like an X.js project and moved it over to data star and they started with a onetoone. So they're trying to actually measure and do this as close as they could. And the thing that's interesting about this um if you go read this blog article these are the numbers like 26 times smaller 26x like that's not percent that's x right 80x less things faster

for mobile fewer production things less of everything right it's just better in every single way and I'm not proud of this like this makes me sad this this is like my side project to solve the problems I want to solve and there's no way that you can have the Googles and Facebooks and versels and they must have the fun fundamental misunderstanding about what the web is and what it can do because I shouldn't be

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 537 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks