Live data from Hacker News

Eventual Consistency in Real-time Web Apps

blog.johnryding.com

11–20 of 27 posts

Re: Eventual Consistency in Real-time Web Apps

#11
post #7

It's a lot simpler to just have the socket, with a notification when your PUT has landed. This is what Meteor does. I don't see anything I recognize as eventual consistency in the traditional sense. It sounds like the client is just trying to receive a stream of updates, which could have been made by a single writer, and the only consistency issues are caused by the different overlapping mechanisms for getting update…

That is certainly simpler.

I will say that our notifications come from a different service that is separate from the service the responds to HTTP requests, which leads to the process that is described in my post.

Re: Eventual Consistency in Real-time Web Apps

#12
I've had a lot of success with embedding initial content for a page as JSON in a script tag with a specific ID and a type of "application/json". This way you can rely on the content being there and sidestep the whole timing issue completely. You can potentially speed up your loading time as well, if you have a bunch of things you'd usually fire additional requests off for.

I believe I got this idea from Backbone's documentation [1] originally, but I've seen it mentioned in other places as well.

[1]: http://backbonejs.org/#FAQ-bootstrap

Re: Eventual Consistency in Real-time Web Apps

#13
post #9
post #5

I hadn't seen the merge / fill idea before. Worth reading to get more ideas on this subject. OT but seems like a good time to ask, does anyone have any experience with Operational Transformations for dealing with syncing in web apps? I've started throwing the idea around for a web app I'm building and it seems like a really interesting pattern. The only real implementation I can find is in sharejs [1]. I work with py…

In general, I've read that OT tends to be very complicated to get right, which is why only a few libraries implement it. If you can use what's called a CRDT, your life will be easier, but there are fewer data structures that are supported. Aral Balkan gave a talk on OT vs a CRDT called WOOT for text editing[1] that I found really helpful. If you want more of the nitty-gritty on some of the different types of CRDT, th…

I'm looking at trying to build something using CRDT; I've had my eye on the field for a while and it seems like by far the best solution.

Yes, you give up generality. But in exchange you get a more natural system with fewer strange edge cases that has good performance and won't lose data under pressure.

Re: Eventual Consistency in Real-time Web Apps

#14
post #10
post #9

Earlier quoted context omitted.

In general, I've read that OT tends to be very complicated to get right, which is why only a few libraries implement it. If you can use what's called a CRDT, your life will be easier, but there are fewer data structures that are supported. Aral Balkan gave a talk on OT vs a CRDT called WOOT for text editing[1] that I found really helpful. If you want more of the nitty-gritty on some of the different types of CRDT, th…

That's great information, thank you. The paper looks really interesting - going to take a little while to get through, might start with the video :) I'd also read that it's hard to get right (I think that was in a comment on HN by one of the people who worked on wave/sharejs). In my case I've limited myself to two different flavours of small object with a limited set of fields (instead of a totally generalised system…

I've not tried it, but you might also be interested in an approach called differential synchronization[1]. Basically, it's just a specific way of passing diffs around to guarantee convergence, though (as far as I can tell) it doesn't guarantee much else (as in do you lose data if a patch can't be applied?). The really nice bits, though, are that it is a simple algorithm and that it can be applied to anything that you have diff/patch algorithms for.

[1] https://www.youtube.com/watch?v=S2Hp_1jqpY8

Re: Eventual Consistency in Real-time Web Apps

#15
post #7

It's a lot simpler to just have the socket, with a notification when your PUT has landed. This is what Meteor does. I don't see anything I recognize as eventual consistency in the traditional sense. It sounds like the client is just trying to receive a stream of updates, which could have been made by a single writer, and the only consistency issues are caused by the different overlapping mechanisms for getting update…

The complexity depends on what constraints you put on yourself. Here's an example, suppose you have a UI panel with a number of checkboxes, radiobuttons, and sliders, and you want to synchronize the state across several users, without blocking (i.e. if a user changes state, he doesn't need to wait for server response to change change state again). Global state exists on a single server. Let's say your users start changing state furiously, what happens? ...well, the object state will live in several places (and slightly different for every client):

1) Local: In the view but before event dispatched to the model.

2) Local: In model but before it was synced to the server.

2a) Local: After model sync and in queue waiting to be sent to the server.

3) Remote: In transit to the server.

4) Remote: On the server (i.e. the one true state).

5) Remote: In transit to the clients.

6) Local: Received but before it was synced to the model.

7) Local: In model but before synced to the view.

8) In the initial state sync (e.g. when a new client joins)

So at any given point, every client state is inconsistent with every other client (maybe even significantly if the latency for one or more of the clients is bad) since pieces of the eventual state are spread across all these locations. If now every user stops changing state furiously, every client should eventually be consistent. It's not a hard problem but not completely trivial. For example, you will need conflict resolution rules on the server and in your client and traditional distributed issues like (temporary) network partitioning and latency need to be taken into account. Message ordering will probably matter.

>It sounds like the client is just trying to receive a stream of updates, which could have been made by a single writer

Not necessarily. You have the same synchronization issues whether the updates are coming from a single source, or from multiple sources.

Re: Eventual Consistency in Real-time Web Apps

#16
post #7

It's a lot simpler to just have the socket, with a notification when your PUT has landed. This is what Meteor does. I don't see anything I recognize as eventual consistency in the traditional sense. It sounds like the client is just trying to receive a stream of updates, which could have been made by a single writer, and the only consistency issues are caused by the different overlapping mechanisms for getting update…

The complexity depends on what constraints you put on yourself. Here's an example, suppose you have a UI panel with a number of checkboxes, radiobuttons, and sliders, and you want to synchronize the state across several users, without blocking (i.e. if a user changes state, he doesn't need to wait for server response to change change state again). Global state exists on a single server. Let's say your users start cha…

The EtherPad UI had a bunch of checkboxes and whatnot that were synchronized live, so I definitely acknowledge the problem. We're working on it at Meteor now too.

The way I look at it, as long as the server has the final say over the "official" value at any given time -- which seems to be the case here, and is true in all real apps I've seen up to the backend datastore's ability to provide it -- you don't really have a consistency or convergence problem. You just have a UI problem. It's easy for the client to track both the latest official value and what the user is doing, and tell the server about the latter. The only question is what to show the user while their action is still outstanding, and the answer may be different for different kinds of UI. You may want to "fake it till you make it" (Meteor's default, aka latency compensation) or show some kind of loading indicator.

What about conflicts? Well, depending on your app, your options for how the server handles operations from the client include: they sometimes fail; they always succeed via "last writer wins" (good for a checkbox, say); they always succeed via operational transforms; or there is application-level conflict resolution that ropes in the user (implemented on top of the foregoing).

There's a trend at the moment to view everything as a distributed system, but if you treat a client as a tool for viewing information and calling APIs, it seems a lot simpler.

Re: Eventual Consistency in Real-time Web Apps

#18

Earlier quoted context omitted.

The complexity depends on what constraints you put on yourself. Here's an example, suppose you have a UI panel with a number of checkboxes, radiobuttons, and sliders, and you want to synchronize the state across several users, without blocking (i.e. if a user changes state, he doesn't need to wait for server response to change change state again). Global state exists on a single server. Let's say your users start cha…

The EtherPad UI had a bunch of checkboxes and whatnot that were synchronized live, so I definitely acknowledge the problem. We're working on it at Meteor now too. The way I look at it, as long as the server has the final say over the "official" value at any given time -- which seems to be the case here, and is true in all real apps I've seen up to the backend datastore's ability to provide it -- you don't really have…

We already have this sort of eventual consistency in Derby, built on top of ShareJS. All documents (JSON objects) can be edited synchronously in the browser, and changes are automatically replicated to all other clients.

If two people make a change to the same documents at the same time, the changes are merged in a way that will never conflict. For example if we both simultaneously insert into a list embedded in some part of the data model, derby sends a "list insert at position X" operation, which is seamlessly transformed & merged into the document at all sites. The insertion position is updated automatically before merging using the same logic that makes collaborative text editing in etherpad work. Except you can do it over the JSON structures that power your web app.

Re: Eventual Consistency in Real-time Web Apps

#19
post #13
post #9

Earlier quoted context omitted.

In general, I've read that OT tends to be very complicated to get right, which is why only a few libraries implement it. If you can use what's called a CRDT, your life will be easier, but there are fewer data structures that are supported. Aral Balkan gave a talk on OT vs a CRDT called WOOT for text editing[1] that I found really helpful. If you want more of the nitty-gritty on some of the different types of CRDT, th…

I'm looking at trying to build something using CRDT; I've had my eye on the field for a while and it seems like by far the best solution. Yes, you give up generality. But in exchange you get a more natural system with fewer strange edge cases that has good performance and won't lose data under pressure.

OT also won't lose data under pressure.

The biggest downsides of CRDTs are that your data ends up much bigger (although usually by a constant multiple), and nobody has figured out how to edit JSON documents using CRDTs yet.

Its not all that surprising that CRDTs will be larger - imagine a stream of operations happening to a document (think about them like tiny git commits, if that helps). You can end up with a lot of changes for a small document (tens of thousands of changes for a single page of text isn't unheard of). CRDTs in effect embed the history of operations into the document, while OT stores them separately. As such, with OT you can eventually migrate the operation log to secondary storage (or throw it away). You can never really do that with CRDTs.

The JSON problem is harder, and obviously very important for realtime web apps that do more than text editing. Decent CRDTs will be trivial to add to ShareJS when they're ready.

Re: Eventual Consistency in Real-time Web Apps

#20

Earlier quoted context omitted.

The complexity depends on what constraints you put on yourself. Here's an example, suppose you have a UI panel with a number of checkboxes, radiobuttons, and sliders, and you want to synchronize the state across several users, without blocking (i.e. if a user changes state, he doesn't need to wait for server response to change change state again). Global state exists on a single server. Let's say your users start cha…

The EtherPad UI had a bunch of checkboxes and whatnot that were synchronized live, so I definitely acknowledge the problem. We're working on it at Meteor now too. The way I look at it, as long as the server has the final say over the "official" value at any given time -- which seems to be the case here, and is true in all real apps I've seen up to the backend datastore's ability to provide it -- you don't really have…

>There's a trend at the moment to view everything as a distributed system, but if you treat a client as a tool for viewing information and calling APIs, it seems a lot simpler.

Ok, I guess I must have misunderstood. If you're the guy whose building on-top some synchronization layer, then yeah, it's not really a problem. The sync layer is just another controller that manipulates your model or another consumer of your model changes.

If you're the guy implementing the synchronization layer, then you are thinking of distributed systems.

Post reply on HN