recogito / text-annotator-js

A JavaScript library for text annotation.
BSD 3-Clause "New" or "Revised" License
15 stars 5 forks source link

Question: Handling of race conditions? #87

Closed lco-sp closed 2 months ago

lco-sp commented 2 months ago

I'm currently building an application based on recogito-js, that is supposed to handle input from multiple clients at the same time. This leads to a range of race conditions though, such as when two users update an annotation at almost the same time (specifically: so long as at least one user has not yet reloaded their local copy of all annotations, i.e. if one user posts an annotation and another interacts with the same text-location without having fetched the first users post), resulting in one update being overwritten by the other. I am running into several of these, in all stages of the create-update-delete lifecycle of an annotation.
As far as I can tell, recogito-js does not handle these race conditions itself, so I'm currently writing backend code to catch some (hopefully most) of them.
Would text-annotator-js be better in handling those kinds of problems, or would I have to catch them with custom code either way?

rsimon commented 2 months ago

Hi, yes, text-annotator-js will be the better option. You'd still need to handle basic merge functionality yourself. (I.e. there is no CRDT built into text annotator directly.) But the state management is much better set up for updating parts of annotations independently, handling remote vs. local changes etc. How you'd handle it would strongly depend on how you are implementing your backend.

In fact I've been building a system for collaborative annotation myself, and that's what prompted the rewrite in the first place. (Here's an example of how we are handling this, using Supabase as a backend.) Another option would be to attach a CRDT like Y.js, I guess. This would make the client part easier, although perhaps complicate the backend.

lco-sp commented 2 months ago

I see! (and thanks for the quick reply)

When you say it "will" be the better option, does that mean that in it's current state, text-annotator-js would not be fully capable of this enhanced state management?

rsimon commented 2 months ago

No, it definitely is already. (We're using it ourselves.) So would would probably be the better word ;-) What I'm trying to say is that it doesn't automagically handle race conditions and merge operations by itself. You'll still need to take care of this with your own code, one way or another. (Either by writing your own event management, or going through a CRDT.) But building such a solution will be easier in the new Text Annotator than in RecogitoJS.

lco-sp commented 2 months ago

Okay, I understand. Thank you!