PhilipAng
← All projects

Driftwood

A collaborative markdown scratchpad that survives going offline.

  • TypeScript
  • WebSockets
  • React

Driftwood is a shared scratchpad for the notes that never deserve a real document — standup jottings, a half-formed API sketch, the three commands you always forget.

Why it exists

Every collaborative editor I tried fell over the moment the train went into a tunnel. Reconnecting meant either losing what I had typed or clobbering what someone else had. Driftwood treats going offline as the normal case rather than the error case.

How it works

Documents are conflict-free replicated data types. Each client keeps the full history of its own edits and merges anyone else's on reconnect, so two people typing into the same paragraph on a flaky connection converge on the same result without a server arbitrating.

The wire format is deliberately boring:

type Op = {
  clientId: string;
  counter: number;
  parent: OpId | null;
  content: { insert: string } | { delete: number };
};

Ops are idempotent and commutative, so replaying the same batch twice is harmless. That one property removed most of the reconnection logic I had been dreading.

What I would do differently

  • The undo stack is per-client, which is correct but surprises people who expect ctrl-Z to undo whatever just happened on screen.
  • I stored ops in a single Postgres table and only added an index once a document hit forty thousand of them. That was avoidable.