Get Started

Build Google-Docs-style live collaboration with CRDTs

Two people open the same document and type at the same time. No spinner, no "someone else is editing", no lost paragraph. Build it yourself with Yjs: a shared document, a tiny sync server and two clients that make conflicting edits and land on exactly the same text. Then take one offline, edit it, reconnect, and watch it merge. You finish knowing why the hard version of this problem needs a CRDT, and why the obvious fix quietly eats people's work.

105 minAdvancedTools: Free. Everything runs on your own PC with Node and three npm packages.Step 1 free
Tested 12 Oct 2026 · Yjs 13.6.33, y-websocket 1.5.4, ws 8.22.0, Node 26.7.0 on Windows 11
A set of small, runnable programs that prove the ideastwo clients making concurrent edits and converging to the identical document, an offline edit that merges on reconnect, and the same edits landing in the same place in any order
A working sync server (y-websocket) and two networked clients that join the same document from separate terminals and stay in step, plus a browser page with two live panes
A clear mental modelwhat a CRDT actually is, why last-write-wins loses data, how it differs from operational transform, and what eventual consistency buys you
  • An honest look at the cost (the metadata and tombstones a CRDT carries) and where to go next for production real-time infrastructure
Before you start
  • Comfort with the terminal and running commands. New to it? Do The terminal survival kit first.
  • Node 18 or newer (this mission was built on Node 26). Check with node --version. The Build your own API lesson is a good warm-up for the build-test-ship rhythm, though it uses Python; this one is all JavaScript.
  • A little JavaScript: functions, arrays and objects. You do not need to know Yjs, WebSockets or anything about distributed systems. Every file is complete and explained.
  • A code editor. VS Code ↗ is free. A browser (any modern one) for the last step.
01/07The problem: two people, one document0 done
STEP 01 of 07~10 min

The problem: two people, one document

Before any code, get the problem clear. Two people editing the same thing at once is not a rare edge case, it is the normal case, and the naive answers all fail in ways you can name.

  1. Picture a shared notes document. You and a colleague both have it open. You add a line at the top; at the same second, they add a line at the bottom. Nobody is waiting for the other. When the dust settles, you both want to see both lines, in the same order, on both screens. That is the whole job, and it is harder than it looks.

  2. The first idea everyone reaches for is a lock: only one person may edit at a time, the way an old shared spreadsheet would say "read only, file in use". It works, and it is miserable. Collaboration stops being collaboration. Google Docs feels alive precisely because there is no lock.

  3. The second idea is to let both edit and have whoever saves last win. We will build that in the next step and watch it delete someone's work in front of you.

  4. The real answer is a CRDT (a Conflict-free Replicated Data Type): a data structure designed so that many copies can be edited independently, offline, in any order, and still merge back to the same value with no central referee. "Conflict-free" does not mean people never edit the same spot. It means the merge rule is defined for every case, so there is never a conflict the software cannot resolve on its own. That is the thing you are going to build on top of.

  5. Set up the project. Make a folder, start a Node project, and install the three packages this mission uses:

    Terminal
    mkdir crdt-demo
    cd crdt-demo
    npm init -y
    npm pkg set type=module
    npm install yjs@13.6.33 y-websocket@1.5.4 ws@8.22.0
  6. yjs is the CRDT library: it gives you shared data types (text, arrays, maps) that merge. y-websocket is a ready-made sync server and matching client. ws is the WebSocket library they run on. npm pkg set type=module lets you use import in .mjs files. The version pins matter here: Yjs clients and servers must speak the same update format, and mixing versions is the most common way this breaks (more on that in step 6).

    TipPrefer not to type every file? The starter kit has all of them, plus the browser page and a README. Unzip it, run npm install inside, and every command below works.
✓
Checkpointnode --version prints 18 or higher, and npm install finishes with a node_modules folder and yjs, y-websocket and ws listed in your package.json.
If it breaks'npm' is not recognised + 2 more
'npm' is not recognised
Node isn't installed or isn't on your PATH. Install the LTS build from nodejs.org ↗, then close the terminal and open a new one.
'Cannot use import statement outside a module'
The project isn't set to use modules. Run npm pkg set type=module, check package.json now contains "type": "module", and save your files with the .mjs extension as the lesson does.
npm install is slow or fails behind a proxy
The three packages and their dependencies are a few MB. On a locked-down network, set npm config set registry https://registry.npmjs.org/ and try again, or use the starter kit on a machine that can reach npm once, then copy the folder.
Still stuck? Ask the community
Next mission · Advanced buildsBuild a rate limiter and API gateway that holds up
→