233 points · by walterbell · 2y ago · 88 comments
https://github.com/braid-org/braid-text/
https://www.npmjs.com/package/braid-text
This is the easiest way to add collaborative editing to a web app. You can add it to any (req, res) handler in your nodejs app. No websocket necessary, since it extends HTTP itself!Plus, it features a new `simpleton` merge-type that requires zero history overhead on the client, and you can implement the client protocol from scratch in just 50 lines of code. There's no reason not to add collaborative editing to every user-editable string in your app now!
All the network traffic is just HTTP, with an open, easy-to-read protocol that supports any OT or CRDT (currently defaulting to josephg's Diamond-Types). You can even read and write directly using the Braid-Chrome extension, which adds a devtools panel to view the version history of any Braid-HTTP resource: https://github.com/braid-org/braid-chrome.
I'm really excited about this library. We were going to announce it tomorrow (at https://braid.org/meeting-86), but since this hacker news discussion is happening... I can't hold myself back from talking about it now!
What does that mean? How do other clients get notified of remote changes?
edit: Braid include its own SSE-like construct, completely incompatible, with a brand-new HTTP status code "209". Seems unnecessary... How does that work with existing servers/proxies/middleboxes?
SSE doesn't work because it (1) doesn't support binary data, (2) assumes that versioning is linear (which doesn't work in a distributed system), and doesn't provide any way to add new headers to each response.
SSE also has an awkward encoding format, but that's neither here nor there.
I don't see what's too fundamentally different about Braid that it needs a new status code and protocol. Shouldn't SSE use 209 then?
You could just as easily base64 encode it (or use your favorite encoding).
> assumes that versioning is linear (which doesn't work in a distributed system),
Whether you're sending SSE frames or subscription events, they arrive in the order the server sent them by virtue of being sent over TCP. Your versioning is an application-level concern, not a transport-level concern
> doesn't provide any way to add new headers to each response.
It's trivial to add headers at the application layer (literally just encode your own "header" to the start of each event). The headers don't need to be a part of the protocol.
But HTTP is a text based protocol. Why do you need binary?
> assumes that versioning is linear
What does linear mean? Afaict SSE ids are opaque strings.
> doesn't provide any way to add new headers to each response
XY problem? Do you really need HTTP headers or do you need a way to pass X from server to client?
I’m not familiar enough with the specific problem, but it’s always good to reuse as much as possible of existing infrastructure.
> Every piece of state has a state:// URL. You can re-use another site's state as easily as linking to a page with today's web. Websites can build on top of one another, and collaboratively outcompete today's centralized monopolies.
If multiple businessses are cooperating to process state owned by multiple websites, how does Statebus envision the encapsulation of state for {user, device, app, feature, business}? Could some state be opaque/encrypted?
What's the best place to learn more about the use cases below, https://stateb.us/why
Built-in offline mode
Collaborative editing by default
Website internal state is opened
Make a new user interface
Implement a blockchain on top of the web
Enables better Email protocol: decentralized, simpler, realtime, spam-free, encrypted
Improves source control:
Source code becomes state—replaces git with the web protocol itself
Any user can edit source for any website, and have their own version
Editable, brancheable, forkable inlineThe language is a bit, idk superlative, but if it does what it says then it would be great.
I started approaching the IETF to learn how to standardize State Synchronization in HTTP. I ran across this HN comment by JosephG [1] making a call to the same mission. I sent him an email, we decided to team up, and we went to dwebcamp in California and then IETF in Montreal together, and made a presentation to the HTTPWG proposing to extend HTTP into a state sync protocol. We got an enthusiastic reception, and I have been working on it ever since.
The HTTP extension is getting into pretty good shape, and we're now manifesting the promises on that /what page. They aren't all production-ready (e.g. no blockchains built on statebus/braid yet), but they are coming true at a steady clip!
Any plans to release a Firefox extension, too? It shouldn't be too hard, IIRC the API is largely compatible.
More generally, I'm unconvinced that synchronization should be so closely tied to HTTP, or that the metadata should be independent of the actual datatypes being synchronized. Any given application is going to need to implement not only a synchronization algorithm, but the datatypes being synced.
Contrast with git, where the data is standardized (file, directories, commits) and it supports many ways of communicating about the data.
(Though, at another level, git doesn't care what's in a file, and that's also true of HTTP.)
It's important for this to be optional. Consider that each keystroke that edits a text resource changes its version ID. You want to be able to link to the text without changing the ID with each keystroke.
It's also important to be able to pass versions within headers of a request or response. The server wants to update the version ID with each update it sends to the client, and that's most elegantly done in a header.
As for your skepticism about integrating synchronization into HTTP instead of embedding it within a datatype, I can empathize -- but you might be surprised at just how elegantly HTTP extends into a full-featured synchronization protocol. A key to this elegance is the Merge-Type: this is the abstraction that allows a single synchronization algorithm to merge across multiple data types.
As an application programmer, you will specify both the data types of your variables (e.g. int, string, bool) and also the merge-types (e.g. "this merges as a bank account balance, or a LWW unique ID, or a collaborative text field"). This is all the application programmer needs to specify. The rest of the synchronization algorithm gets automated by middleware libraries that the programmer can just use and rely upon, like his compiler, and web browser.
I'd encourage you to check out the Braid spec, and notice how much we can do with how little. This is because HTTP already has almost everything we need. Compare this with the WebDAV spec, for instance, which tries to define versioning on top of HTTP, and you'll see how monstrous the result becomes. Example here: https://news.ycombinator.com/item?id=40481003
I'm also a little unsure of why "partial PUTs" are needed. "PUT an update as a patch" seems like exactly the use case for PATCH. Not that it super matters either way as far as compatibility is concerned, but it feels like it's contorting PUT to do what PATCH already accomplishes
PATCH is supported in Braid, but only works for client->server. It does not support updates from server->client. So we need a way to express general updates, in both directions. Braid lets you use existing PATCH specs (as Patch-Type) if you want.
The PATCH specification also confounds multiple concerns (versioning, conflicts, validation, data formatting, applicable data types) into a single spec. It's nicer for these aspects to be modular and independent. Partial PUT happens to be already a modular, independent way to specify just the patch format, and can be extended to new data types by "Range Units." But use PATCH if you prefer!
Braid is not trying to be "application logic" or "transport protocol" -- it is a State Synchronization Protocol. If you can think of a more elegant method to support all of state synchronization within SSE, we're all ears!
But AFAICS you end up having to embed base64-encoded HTTP responses within SSE events within HTTP responses, which is gross pile of russian dolls, where both the innermost and outermost dolls are the same type of doll -- an HTTP response! So why all the intermediate dolls?
It's more elegant and simpler to extend HTTP at the root level, and say: "Instead of returning 1 HTTP response, a Braid server can return N HTTP responses, concatenated together with optional newline separators."
I kind of think sometimes it makes more sense to layer on top of http instead of extending.
WebDAV didn't really catch on, but the general product space of remote drives did. The problem with WebDAV is that like most Web* tech (and maybe Braid) it's design by committee in the abstract. To make remote drives work well for the end user requires a fairly complicated protocol with tons of ugly edge cases. The interoperable standards from committees approach tends to fail in those situations, whereas hard driving startups that use proprietary protocols they can iterate quickly tend to win.
Iteration speed > openness, when there's nothing to copy from. Standardization tends to be about bigger companies trying to commodify their competitors.
Didn't you mean to commodity their complements? Like when Microsoft (software company) commoditied the hardware on top of where their OS ran.
Let's compare WebDAV with Braid for something simple like looking up the current version of the resource.
In WebDAV, you have to:
- Send a PROPFIND request to the URL of the resource you want to check. In the request body, specify the DAV:version-controlled-binding property you want to retrieve, using a custom XML syntax. Here's an example:
PROPFIND /path/to/resource HTTP/1.1
Host: example.com
Depth: 0
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8"?>
<propfind xmlns="DAV:">
<prop>
<version-controlled-binding />
</prop>
</propfind>
- The server responds with a 207 Multi-Status response, with XML to parse: HTTP/1.1 207 Multi-Status
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:">
<response>
<href>/path/to/resource</href>
<propstat>
<prop>
<version-controlled-binding>
<href>/path/to/version/history</href>
</version-controlled-binding>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>
This does not yet give you the version -- it tells you a separate URL that contains the version history. So now you have to query that for the version:- Send a REPORT request to that url, and in the request body, specify the DAV:version-tree report you want to retrieve:
REPORT /path/to/version/history HTTP/1.1
Host: example.com
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8"?>
<version-tree xmlns="DAV:">
<prop>
<version-name />
<creator-displayname />
<creation-date />
<comment />
</prop>
</version-tree>
- The server responds with a 207 Multi-Status, with more custom XML for you to parse: HTTP/1.1 207 Multi-Status
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8"?>
<multistatus xmlns="DAV:">
<response>
<href>/path/to/version/1</href>
<propstat>
<prop>
<version-name>1.0</version-name>
<creator-displayname>John Doe</creator-displayname>
<creation-date>2023-05-26T10:00:00Z</creation-date>
<comment>Initial version</comment>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href>/path/to/version/2</href>
<propstat>
<prop>
<version-name>2.0</version-name>
<creator-displayname>Jane Smith</creator-displayname>
<creation-date>2023-05-27T14:30:00Z</creation-date>
<comment>Updated version</comment>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>
You can find the versions in there, and if you then parse and filter to the most recent version, you can see that the current version is 2.0.That was a LOT of work!
Now let's see it in Braid.
To get the current version, just do a normal GET or a HEAD, and look at the Version: header in the response:
Request:
GET /path/to/resource HTTP/1.1
Response: HTTP 200 Ok
Version: "2.0"
<body of resource>
That's it! It's that simple!Braid is this simple because it is baked into HTTP. It turns out that HTTP itself is already very close to a State Synchronization protocol -- it just needs a few headers, and the ability to stream updated responses when a resource changes. I encourage you to check out the spec, and see how easy it is to do things that were complicated or impossible in WebDAV:
https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-b...
Looks really stupid when transfer-encoding chunked already exists for exactly this use case.
Some people have suggested using chunked boundaries as a way to encode multiple responses to a subscription. Perhaps this is what you are thinking of. However, chunk boundaries cannot be relied upon to remain intact; they can be changed by intermediaries. The chunks are only an encoding of the transfer. They are not supposed to contain any semantic information.
Chunked transfer is also disallowed in http/2.
Looks interesting to me, seems nice to be able to handle refreshing content with pure http as described here rather than with web sockets.
https://datatracker.ietf.org/doc/html/draft-toomim-httpbis-b...
> Together, these features enable a web resource to synchronize automatically across multiple clients, servers and proxies, and support arbitrary simultaneous edits by multiple writers, under arbitrary network delays and partitions, while guaranteeing consistency using an OT, CRDT, or other algorithm.
So, you'd use it if you want to "support arbitrary simultaneous edits by multiple writers, under arbitrary network delays and partitions, while guaranteeing consistency", for example for apps that want to support collaborative editing.
Braid wants to turn state transfer (like in RESTful API designs - Representational State Transfer) into a kind of synchronization transfer for state. Currently, state synchronization is handled on the state management layer of each individual application, and API calls just transfer that state, but Braid wants to have it solved as an extension to HTTP libraries on the API layer of an application AFAICS.
Braid is transitioning HTTP into a peer-to-peer world, where the distinction between clients and servers doesn't matter.
HTTP was invented for static pages, that were written by hand, and rarely changed. But today's web has dynamic pages, driven by javascript and databases, and users expect them to update in realtime. Braid-HTTP adds support for dynamic state to HTTP.
But to be fair, we're not a company, but a working group. And we don't hate hypertext, we just haven't gotten around to implementing server-side rendering, which would be a nice thing to do.
What on that page of just text and images made you feel an entire application was appropriate instead of just a hypertext document? I hope this application-centric approach isn't also being applied to the HTTP extension. Hypertext documents should at least get an equal share of the consideration for an HTTP protocol.
I get that for commerce HTTP is just a transport to deliver the javascript/json/etc application. That's the way things are. But HTTP in general has to handle more use cases than just commerce.
I worry that adding this dynamic checking of state to HTTP itself will make websites that adopt it inaccessible and unusable for almost every browser that currently exists. Only new software will be able to use them. It's a substantial break. Maybe don't call it HTTP.
We have been using our own protocol "FeedAPI" for broker-less, multi-service event sourcing over HTTP. But it is a bit home-grown, would be great if event sourcing over HTTP was a more widespread thing with a common standard. There are so many scenarios where event streaming is a great model, but deploying Kafka is overkill, or would couple together the infra too much of publisher and consumer (e.g. different between organizations).
See our current work on the "feed" spec in Braidmail: https://braid.org/apps/braidmail/spec2.
To support event-sourcing, you could replace those {link: ...} objects with event objects, and just treat each event as data. Then you'd have a url like /event-stream that peers would subscribe to.
Or, you could go deeper, and come up with a custom `Patch-Type:` for your events, which could make your events first-class HTTP citizens that could also be applied to a server using the PATCH method. Then your url might be /system-state, and represent the state for the whole system.
Braid supports such custom events, but be aware that this model is limited in a few ways:
- It's less interoperable, because all peers must know and implement the custom event types (aka patch-type) in order to read or write state.
- You don't get to re-use the beautiful and complicated merge algorithms that support eventual consistency with multiple writers (the OT/CRDT algorithms).
- It doesn't allow summarization of history. It's hard to prune history when each peer needs to know all events in order to do anything.
You might also be interested in PREP, which is a pure event-update protocol being worked on by my colleague Rahul Gupta: https://github.com/CxRes/prep We're trying to merge our work together, if we can.
You might also be interested in our deliberation on the pros/cons of "events" vs. "state updates" here: https://github.com/braid-org/braid-spec/issues/102#issuecomm...
Braid: Synchronization for HTTP - https://news.ycombinator.com/item?id=26385480 - March 2021 (1 comment)
Braid: Synchronization for HTTP - https://news.ycombinator.com/item?id=21626261 - Nov 2019 (47 comments)
> Braid-HTTP is an extension to HTTP that generalizes it from a state transfer to a state synchronization protocol.
They could simply say it's a synchronization protocol over HTTP.
The HTTP acronym stands for HyperText Transfer Protocol. ReST stands for Representational State Transfer.
HTTP began as a HTML Transfer Protocol, but then generalized to content-types beyond HTML, such as images, scripts -- and general state. So today HTTP is known as a State Transfer Protocol. This architecture was canonicalized as ReST in Roy Fielding's dissertation.
In order to generalize HTTP from State Transfer to State Synchronization, we have to augment some parts of it, such as request/response. Instead of just getting a single response to a request, Braid allows a client to subscribe to a resource, with a single request which will be then given multiple responses -- one response for each update to the resource.
It is quite elegant to extend HTTP at this level! And we can do so without requiring any changes to web browsers.
Can it prune history?
What if I write a todo application in it, and one of the clients will connect only once a month? What about a client that will drop and never return? (in some systems it means past updates will pile up indefinitely, and state on other clients will keep growing)
Indeed, text sync requires old history to merge with old edits. However, Braid does not force you to hold everything. Peers can implement their own policies for deciding who to sync with. They can also ask each other for modules of old history they've forgotten if they realize they need it to merge something. This is made possible with the new Time Machine architecture that we are writing up.
This architecture also allows you to sync at multiple time resolutions -- realtime, fine grained, or slower, course grained -- within the same system. Different peers can hold and share at different resolutions. And they can all guarantee consistency with each other in the end. See the recent simpleton algorithm work for an example.
This algorithm is the first to do so, and happened to be developed in the Braid group.
As for scaling, check out JosephG's https://josephg.com/blog/crdts-go-brrr/ CRDT, which scales great, and is thoroughly tested. The Braid protocol is also architected with a new type of OT/CRDT architecture called a Time Machine that lets you do advanced things like apply backpressure through a network to decrease the frequency of updates, which we presented in https://braid.org/meeting-81, and are releasing in the https://github.com/braid-org/braid-text library that you can try right now.
I'm sorry to criticize but who is this article written for? It's either so dense that you already need to be an expert to unpack all the information, or the information is not there.
I would recommend starting from the assumption that the Hacker News layman knows the http protocol. Make sure what you show us is possible to follow from some reasonable starting point.
Braid proposes new HTTP headers that give HTTP new features, so that instead of just being a State Transfer protocol, it gains the functionality to become a full State Synchronization protocol.
To "extend" a protocol means to add new features to it, e.g. with new headers, which doesn't break existing uses of the protocol, but allows new implementations to opt into new extended functionality.
HTTP was originally stateless, but then added cookies. Over time, web apps evolved to store tons of state in databases on the server. Then they started storing tons of state in javascript variables and DOM on the client. Today, most of the code we write in a web app is there to synchronize the changing state on a server with the changing DOM on the client. The web is no longer static pages. It is dynamic state. But since we haven't extended HTTP to support dynamic state, programmers have to write all this synchronization code by hand. This has been a pain in the ass, and so we've evolved monstrous stacks of Javascript frameworks (react, redux, etc. etc.) to try to help manage this state synchronization from server to client. If we build this functionality directly into HTTP, tons of code goes away, and the web itself gains great new features. Then, since we will have a standard for state synchronization, our state can interoperate, and walled siloes of websites break down. We can have a P2P web.
When this work is complete, the browser will no longer need a reload button. The browser/server will guarantee that every page is always up-to-date, and every peer that synchronizes with that state will have an equal copy.
I think this is skipping over some tricky UI issues regarding updates. For a text-heavy page, maybe you don't actually want a web page to jump around while you're reading it? Maybe there should be a live indicator to indicate that there are new updates, along with a reload button that lets you decide when you want to see them?
Browsers themselves do similar things - they let you know there's a new browser version, but you don't have to click "update" right away. You can finish what you're doing.
Contrast with video games where things are expected to move around. The visual design is different. There are animations so that you can track objects moving around.
Another example: recently I had been playing around with automatic syncing of a web form so that the user wouldn't be editing stale data, but I realized it was confusing so I took it out. For a form, a good time to inform the user that there is an edit conflict is when they press the "submit" button. People expect to see form errors at that point. But live edit indicators and a reload button might be good too?
Or what if you're reading a web forum, switch to another tab, then come back again. Should the page automatically refresh when it becomes active? Maybe, maybe not. It could be confusing. Maybe the new messages that appeared while you were away should be indicated somehow?
For these reasons, I'm skeptical of automatic browser syncing. I think the web app designer needs control over how to apply live updates.
Much like mobile apps were not just desktop apps scaled down, live web pages require different UI conventions. Maybe new HTML widgets?
walterbell
nearly all criticisms responded to by a (the?) toomim brother, (who styles himself an independent psychology researcher, interesting) plus an appearance by mike_hearn.
Why is this proposal to significantly extend the scope and basic functionality of http so popular with bitcoin promoters?
Thanks to your left field comment, I've learned from Algolia that my HN submissions and comments include the terms "bitcoin" ~0.3% and "cash" ~1.3%.
> nearly all criticisms responded to by a (the?) toomim brother
Co-author of the technical proposal? It's usually good to see the author of a technical article providing substantive responses to HN comments. It's also good to have more feedback on the substance of the article. Any comments on the technical proposal?
> Why is this proposal to significantly extend the scope and basic functionality of http so popular with bitcoin promoters?
This draft proposal could benefit from contribtors from more than one organization (Invisble College), but at least there appear to be multple implementations of the proposed protocol, as is typical of IETF drafts.
But I was struck by the preponderance of questions from other HNers in this comment section, all of which seem to be categorized it under the rubric, "what's the point of this?" It was only then that I noticed the connection between the few people making most of the answers to those questions, as well as the submitter.
So I ask again, why are Bitcoiners so clustered around this project?
As the submitter, what connection are you referencing? Your comment thread is the first I've answered on this article. mike_hearn has one (1) answer. That leaves responses from the author of the article, i.e. one person. Where are the "few people" to whom you are alluding?
> questions .. seem to be categorized it under the rubric, "what's the point of this?"
Given the effort involved in any IETF draft proposal with at least two competing implementations of the protocol, this is a good question. Since learning about this project 10 hours ago, when the story was submitted, I'm still trying to understand use cases beyond "less complex" than alternatives. Based on the HN responses, it's not a well known project, so it would benefit from wider evaluation and feedback.
Work on substantive protocols for P2P decentralized publishing is always welcome, especially in 2024 when LLMs and "AI" are consuming available oxygen. If there is some (unstated?) connection between the proposed protocol and digital payments/assets, then protocol security and access control deserve close attention.
Is it like GRPC as a protocol, built on top of HTTP/2?
I’d be interested in working on a port for .NET.
That’s what we want for braid. Braid is an extension of http which adds semantics for documents and data that change over time.
(I’m no longer directly involved, but I really hope the project succeeds!)
Most of the implementations are in Javascript. Check out braid-text, it's super practical: https://www.npmjs.com/package/braid-text
There are also implementations in Rust and Go.
The python community tends to be less neophilic than JS (often to its advantage) so I wouldn't expect that to show up until later.