Everyone viewing this page can see your edits live. Open this in another browser window for maximum wow.

Here’s etherpad in 4 lines. Loading. (Or its probably broken and you should come back later.) Everyone viewing this page can see your edits live. Open this in another browser window for maximum wow.

ShareJS is an Operational Transform library for NodeJS & browsers. It lets you easily do live concurrent editing in your app.

You’re writing a web app. Your app contains data that users edit. Your users should be able to user your app from multiple computers if they need to. Sometimes you want multiple users to view & edit the same data.

How do you make that work, without the data going out of sync and without losing anything?

One option is to have Submit buttons everywhere. Stackexchange, Reddit and Hacker News work like this. You can’t write half a HN comment from your laptop and half from your phone. Most wikis have a ‘save’ button and do locking. Its like the ghostly hand of visual sourcesafe has somehow infected the web with sloppy engineering and a terrible user experience. If your wiki lock expires while you’re doing a big edit, you're in a world of hurt.

The solution is Operational Transformation (OT). If you haven’t heard of it, OT is a class of algorithms that do multi-site realtime concurrency. OT is like realtime git. It works with any amount of lag (from zero to an extended holiday). It lets users make live, concurrent edits with low bandwidth. OT gives you eventual consistency between multiple users without retries, without errors and without any data being overwritten.

Unfortunately, implementing OT sucks. There's a million algorithms with different tradeoffs, mostly trapped in academic papers. The algorithms are really hard and time consuming to implement correctly. We need some good libraries, so any project can just plug in OT if they need it.

I am an ex Google Wave engineer. Wave took 2 years to write and if we rewrote it today, it would take almost as long to write a second time. (What??)

Enter ShareJS. ShareJS is a simple (~4k LOC) coffeescript server & web client library for OT. With ShareJS, your website can let your users collaboratively edit text documents and arbitrary JSON data in realtime. (Like this one.)