Real-time systems

Pushing an update to a browser is easy. Deciding whose version is correct when two arrive at once is the entire discipline.

Concurrency is the real subject. Two people editing the same paragraph, or two operators changing the same record, produce conflicting intentions, and something must resolve them deterministically. Last-write-wins is simple and silently destroys work. Operational transforms and CRDTs preserve both intentions and are considerably more complex to implement and to reason about. Which you need depends on whether the thing being edited is a document, a list or a single value — and that decision belongs at the beginning, because it shapes the entire data model.

Connections are not the reliable thing developers assume. A websocket drops when a laptop sleeps, a phone changes network, or a proxy decides an idle connection is dead — so reconnection with state resynchronisation is not an enhancement, it is the baseline. The correct mental model is that the client is frequently behind and occasionally wrong, and the protocol has to let it catch up without replaying everything since the beginning of the session.

Presence — who is here, who is typing, whose cursor is where — looks like a small feature and is the one that scales worst. It is high-frequency, low-value traffic, and the naive implementation broadcasts every cursor movement to every participant, which is fine for three people in testing and collapses at thirty. Throttling, batching and being willing to be slightly stale are what make it viable, and they are much easier to build in than to retrofit.

How we work

  • The conflict-resolution strategy is chosen against what is being edited, and chosen first, because it shapes the data model.
  • Reconnection and state resynchronisation are part of the protocol, not an error path, because connections drop constantly.
  • Presence traffic is throttled and batched from the start; the naive version works for three people and fails at thirty.

What this includes

Pick what you need and send it over.

Related