Fly.ioProblem & solution
Real-Time Collaboration with Replicache and Fly-Replay
Summary
Distributed real-time collaboration becomes difficult when a single server coordinating document changes is overloaded and documents must be split across machines without exposing routing complexity to clients. This demo combines Replicache, a custom WebSocket endpoint, Fly Machines, and the Fly-Replay header to route each document’s connection through a shared router to the machine responsible for that document. The server keeps connections by spaceID, sends initial and incremental state, and tracks messages already delivered; the client overrides Replicache’s push and pull handlers to exchange data through the persistent socket. The resulting application has React frontend, Express router, and Replicache/WebSocket backend layers, with each todo list assigned to one backend machine. The author cautions that the approach is demonstrated only in a basic demo and should receive serious production testing and tuning.
Context
A single server coordinating users’ changes for each document can become overloaded as the application grows. Splitting documents among servers introduces the need to route each document’s client connections to the machine that stores it, without requiring clients to know the backend location.
Approach / What changed
A shared Express router uses the Fly-Replay header to forward a WebSocket upgrade request to the Fly Machine assigned to a document. The backend stores connections by spaceID and synchronizes Replicache state over WebSockets, while client-side push and pull handlers are overridden to use the persistent connection instead of HTTP.
Takeaways
The backend sends a client’s complete initial state, then tracks delivered messages so later updates can contain only changes the client has not already seen.
The demo uses three layers: a React frontend, an Express router, and a Replicache/WebSocket backend running across Fly Machines.
The author says the implementation has only been tested within the basic demo and should not be used in production without serious thought and tuning.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.