https://chrismalek.me/posts/data-star-first-impressions/ Skip to main content Chris Malek - Tech Writings * * * * Home About Tags Posts Datastar: Web Framework for the Future? 2025-01-15 [Last modified: 2025-01-20] /posts/data-star-first-impressions/ map [email:chris.malek@cedarhillsgroup.com location:San Diego, CA name:Chris Malek] * #Datastar * #hypermedia Table of Contents * TLDR * Introduction + My Background * What Am I looking for? + My First Impressions of HTMX * Revisiting Datastar and a Turning Point * What is Datastar? + Comparing to HTMX + What is a "Signal" and what is "Reactive Programming"? + Understanding Reactive Programming via Spreadsheets * Actions - GETS/POSTS/PUTS/DELETES + Understanding SSE - It is just text + Example of a Datastar Application * Rethinking Web Development * Server Requirements + Additional Considerations * Conclusion * Further Reading # TLDR Datastar is a new hypermedia framework that makes building real-time web applications simpler and more efficient. It prioritizes server-side logic, uses "signals" for automatic UI updates, and leverages Server-Sent Events for lightning-fast performance. If you're looking for a streamlined alternative to traditional JavaScript frameworks or HTMX, Datastar is worth exploring. However, it requires that you approach web development with a fresh perspective, embracing server-driven architecture and reactive programming. # Introduction I've been diving into hypermedia lately looking at frameworks and libraries to build a new product and to help quickly create proof of concepts and web tools for clients. HTMX at the time of writing was getting basically all the attention in the Hypermedia world. It demos really well and the examples are great. However, this article is NOT about HTMX. I believe hypermedia and HTMX offer a promising direction, but when I tried to develop a new product using HTMX, I felt stuck due to challenges in figuring out the project structure, the HTML structure combined with excessive HTMX tags and realizing HTMX cannot handle the front-end interactively for which you have to bring in something like AlpineJS. (Did I mention I hate javascript?). HTMX is cool but I think before you start a new project with it you might want to look at Datastar as well. I had looked at Datastar in the past while evaluating HTMX but I did not grasp its potential over HTMX until I took a second look at started to feel some HTMX pain. Your results may vary. ## My Background First let's understand my biased perspective. Everyone's background is different and I think it is important to understand where I am coming from. * I am an expert in the PeopleSoft ERP platform creating "enterprise" applications + PeopleSoft is a large ERP system that is used by many large organizations. It is a very powerful but a bit dated. Since it is the hub of most corporate data it is not going away anytime soon but SAAS apps are slowly chipping away at it. + I spent most of my time creating business CRUD applications that are used by business users and students. + These are always "config" driven because PeopleSoft makes it easy to create setup/config tables and GUIs to manage the data. Think of PeopleSoft has one big ball of "feature flags" in the form of setup tables. + PeopleSoft completely abstracts the front-end away. You never worry about the front-end. The back-end controls the front-end. PeopleSoft was built 30 years ago and it's meta-data architecture allowed the porting from a client-server architecture to a web architecture. Developers can deploy applications and never worry about JavaScript or even HTML and CSS at all. This is amazing. o This has kept me away from the front-end for most of my career. I have always been a back-end developer but with PeopleSoft a back-end developer can easily deploy front-end user-facing applications. So I am used to handling and delivering solutions to clients that are 100% server-side but also user facing. You don't need a front-end developer to deploy a PeopleSoft application. + These applications contain some of the most sensitive corporate data from payroll, biographic data, student data, financial data, etc. You cannot "move fast and break things" in these applications. You have to be very careful with the data and the business logic. + In these applications, you cannot trust code running in the browser and your backend code must protect access to the data. * I use Go for most of my side projects. I like the simplicity, speed and type safety of Go. # What Am I looking for? I have been looking for a framework or a set of libraries to build a new product that is modern and efficient. I had been looking at Hypermedia to do this. My rough requirements are: * A modern web framework that is efficient and can handle real-time updates. * A framework that can handle the front-end and the back-end but rely 100% on the back-end where possible. * A framework that can handle the front-end state and interactions. * Simplicity, Simplicity, Simplicity * A framework where I can use Go on the back-end. * Rapid development and prototyping * Avoid Javascript and NPM as much as possible or totally from a development perspective. + Javascript makes me queezy and every time I see NPM I get a headache and my instincts tell me to run away. I am not a fan of the JavaScript ecosystem. * A "stable" platform that I can deploy something and just have it work for years without me worrying about it. * Rapid deployment to the cloud like Fly.io. * Freedom to use any CSS framework I want because those seem to change with the wind. * Avoid the split-team, JSON API approach of modern web apps where frontend and backend are disjointed. Previously I was looking at Phoenix but did not want to shift to another language. If you google "hypermedia" you will see a lot of articles about HTMX and it seems GitHub is full of projects using it. I think it is the most popular hypermedia library at the moment. I had looked hard at the Live Golang Library . ## My First Impressions of HTMX Of course, I looked at HTMX and started to get excited about its potential. So I started to develop a real application after deploying some fairly simple "web tools" that my clients use for some one-off tasks. I created some simple tools for myself and clients. I did not need any front-end state or interactions. I was just updating the UI with new HTML fragments from the server mostly as a result of field change or clicks. In these simple cases, HTMX handles those well. In my HTMX prototyping of a more complex application, the HTML code became a mess with HTMX tags for some parts that were non-trivial. I found myself struggling to understand the project structure and myriad of HTMX tags and how to manage the front-end and the back-end. I also needed some front-end functionality and state and HTMX is NOT designed to handle that. With HTMX you have to import AlpineJS and I broke out in hives because I hate JavaScript . It was when I got to the more complex parts of the application that I felt HTMX was sort of getting in the way. I was starting to a get a huge lint ball building up. My intuition told me I was headed in the wrong direction. I hit the pause button and started to look for alternatives because I felt I was working too hard and the code was getting too complex. # Revisiting Datastar and a Turning Point I was busy working at client sites and I had put a pause on my research for HTMX alterntives or some non-trival TODO application examples. Then on my YouTube feed one day, I saw an interview with creator of Datastar , and it had me look again. If I had not had some experience with HTMX I would not have "been ready" for that interview and understood some of the points he was making. Here are some AI Generated main points of the interview. The ones I put in bold are the ones that got me to look again at Datastar: 1. Delaney explores hypermedia beyond HTMX, focusing on real-time applications. 2. HTMX is seen as solving 1999's hypermedia issues, but not pushing current boundaries. 3. Server-sent events (SSE) offer efficient real-time updates, surpassing traditional AJAX. 4. Datastar, a modular alternative to HTMX, aims to simplify code and enhance performance. 5. Game development's efficiency can inspire web development's speed and capability. 6. SSE enables microsecond updates, challenging the limitations of polling in HTMX. 7. The event-driven architecture is vital for scalable, efficient, real-time applications. 8. Datastar's declarative approach reduces complexity compared to HTMX. 9. Emphasizing server control, SSE can optimize and simplify web interactions. 10. Delaney argues for a paradigm shift towards smarter use of hypermedia technology. I had looked at the Datastar documention previously when I was evaluating HTMX. I probably found it from some discussions on Reddit. However, I previously struggled to grasp its purpose and found its documentation confusing and dense. Honestly, I think it was just over my head when I first read the Datastar docs. I was not ready to understand it. It claims to be a better alternative to HTMX and AlpineJS. Another thing that turned me off was the project did not have a huge amount of contributors. However, after watching the interview from the Datastar author, I realized he might have some serious insights and I should give it another look. He is also a contributor to HTMX. The two things that I originally found confusing about Datastar were: * Use of SSE (Server-Sent Events) for real-time updates. + I had no experience with SSE and didn't understand how it could be used in a real-time application. I had some vague memories from reading about how they did not scale or they suffered from issues with the connection being dropped. I had not looked at them in years. I have zero experience with them. * The concept of "signals" for reactive programming. + I did not realize how this can drastically simplify your code. + The term signal was confusing and I just did NOT get it on the first read. I had no experience with reactive programming. It turns out signals can help me avoid a lot of front-end code and state management but I did not realize that at first. That interview had me look at the documentation again which had undergone some updates. After I spent some time reading and re-reading the documentation and looking at the examples then trying some "hello world" examples on my own then the light bulb went off. Datastar might be the library I had been looking for. It looked promising after I started to peel off some onion layers. # What is Datastar? It seems the author delaneyj is taking some base primitives of HTMX and Hypermedia and making it easier to use and Datastar is his answer. Those are the claims at least. At the time of writing, I am still creating my first application with it. I am not ready to give a full review. But I am excited about the potential. It seems that the Author is also a big fan of Go which helps me because any examples and libraries will have Go examples. First let me clarify. I am not an expert in Datastar. I am just starting to learn it. I am also NOT a contributor or author to Datastar in any way. I am NOT taking any credit. I just want to spread the word about it as I don't think it is getting the attention it deserves. From my current understanding of Datastar, there are some key concepts that form the foundation of Datastar: * Signals: Reactive programming primitives that automatically update the UI when data changes. + We will explore what the heck these are shortly. + You as the developer will decide what signals you want and put some special tags on the HTML elements that will trigger the server to send back updates to the signals. This will be associated with some sort of server state. * Server-Sent Events (SSE): Efficient data streaming for real-time updates and page changes. + These are just the repsonses sent back from the server to the client. They are just text over HTTP and are generally HTML fragments that update the UI. You can do many other things but let's not get ahead of ourselves. * Actions: HTTP verbs (GET, POST, PUT, DELETE) that trigger server-side logic and UI updates. + These are the HTML tags that you put on HTML elements that trigger the server to send back updates to the signals or new HTML fragments that update the UI. * Fragments: HTML snippets that update the UI based on server-side logic and user interactions. + Your server side has to be structured to send back these HTML fragments that will update the UI. You include the Datastar JavaScript library in your HTML and then you can start to use these concepts to build your application. You will also need to structure your server to handle the SSE requests and the GET/POST/PUT/DELETE requests. Your backend choice does not matter. ## Comparing to HTMX I will mostly compare it to HTMX because that is the current perspective I have and HTMX is getting a ton of ink and attention. * With HTMX to build a real application you need: + Front End o HTML o HTMX JavaScript and Tags to handle the triggers to backend updates o AlpineJS (or other JavaScript framework) to handle front end logic and interactions and state. + Backend o HTML fragments that are that is dependent on your UX o Routes and Code to handle the GET/POST/PUT/DELETE * With Datastar to build a real application you need: + Front End o HTML o Datastar JavaScript to handle the triggers to backend updates and all the UI state and interactions. + Backend o HTML fragments that are dependent on your UX o Routes and Code to handle the GET/POST/PUT/DELETE o SSE routes to handle the updates to the signals So just from looking at the dependencies, Datastar gives you a single JavaScript library that can handle state on the front-end (signals) and making HTML attributes perform actions (GET/POST/PUT/DELETE) and handle the updates from the server. The server is 100% responsible for generating the HTML fragments and the updates to the signals. * Datastar provides the benefits of HTMX and AlpineJS under a single library. You get the best of both worlds. * You can ditch much of what a front-end framework like React or Vue.js would provide and use Datastar. (Bold claim) * Your server is 100% responsible for generating HTML snippets and templates very similar to what you would do with HTMX. * It is back-end agnostic and can be used with Go, Node.js, PHP, etc. I prefer Go but it does NOT matter. * It relies heavily on Server-Sent Events (SSE) for real-time updates but after you pull the cover off of SSE it is just text HTTP responses with a some different headers. ## What is a "Signal" and what is "Reactive Programming"? I think one of the biggest things that I missed in my initial read of the docs was the concept of a signal. This was not invented by Datastar and I believe is implemented in Datastar using a library from another developer. I'm sure I'm just behind the curve and you may already know what a signal. I'm going to try to explain it. Getting an fundamental understanding of what a signal represents and can do for you is what give Datastar its power. It makes creating user interfaces much simpler and more maintainable. Before we talk about signals, let's talk about reactive programming because they are related. Reactive programming makes your application code automatically "react" to changes in data and propagate those changes automatically through the application. Instead of telling the computer how to do things step-by-step, you tell it what should happen when data changes and the computer figures out how to do it. It allows you to define a relationship between data sources and data consumers. When the data source changes, the data consumer is automatically updated. In a non-reactive system, you would have to manually update the data consumer when the data source changes. This is generally in the form of "on-change" Javascript events and functions to bind all the data and UI together. Ok, Ok that is still too much jargon!!!! ## Understanding Reactive Programming via Spreadsheets I think the best way to understand reactive programming is to think about a spreadsheet. * A spreadsheet application like Microsoft Excel or Google Sheets is the best example here. + If you have any experience working with a complex spreadsheet in the engineering or financial realms, you have already worked with reactive programming. + I am NOT talking about using excel as a CSV viewer. + I am talking about using it as a tool to do calculations, and you "build up layers" of intermediate calculations to get to a final result. o Very often you have intermediate calculations you need for other calculations or just doing checks for mistakes. This leads to a series of calculations that are dependent on each other. This is represented in formulas in spreadsheet cells that reference other cells. For complex calculations, you can have a "pipeline" or spiderweb of calculations that are dependent on each other. o I have an engineering degree and worked for engineering firms while in college and after college, I have used Excel for some very complex calculations and engineering modeling for HVAC cooling and plumbing systems. Excel is an great tool for this. The amazing thing about Spreadsheets is that it is reactive. When you change a value in a cell, all the dependent cells are automatically updated. This is the essence of reactive programming. In you define the relationships between the "cells" or data elements and the underlying framework progates changes when data changes. This is very powerful and can simplify your code and make it more maintainable. Here is a rough schematic of that where the arrows represent the dependencies between cells: diagram Datastar gives you some of these some of these same capabilities in a web application via the concept of a signal. I conceptually think of a Datastar signal as a link between "cell" or HTML elements. I did not make this connection at first. * In Datastar, signals are used to update the UI when the data changes. * It can also trigger back end posts/gets/puts/deletes. Signals are part of the glue of a Datastar application. You place signals on the page and the UI can be automatically updated. See the Model Binding Example and the Signals change example The server can send down updates to the "signals" (spreadsheet cells contents) or even send down a new HTML fragment that update the UI. In spreadsheet terms, this would be like adding new cells, charts, etc from the server. There is more you can do with signals. If you read the docs and still don't understand, I would re-read them. I had to read them a few times to get it. # Actions - GETS/POSTS/PUTS/DELETES When/if you start looking at HTMX you see that you can trigger actions on the server with a GET/POST/PUT/DELETE. This is the same in Datastar. You can trigger these actions with a signal. HTMX and Datastar both trigger this server request to the server to update or get updated UI elements. The difference is that Datastar uses SSE to get the updates back to the client. I was scratching my head on this until I started reading more about it and looking at the examples. SSE is very simple. It is just text which I maybe had read before but since I had no real experience doing development work I did not understand. I work daily with HTTP web services and have a firm grasp on how HTTP works. You can add some "tags" to the HTML elements (button on click, input on change, etc) and then when the user interacts with the page, the server can send down updates to the signals. From the Datastar examples :