← All assets

Infrastructure

Gravity Sync

Peer-to-peer multi-master replication for code projects. Every node is equal; there is no server in the middle.

Prototype
1.0.0
Version
1,441
Lines of code

across 10 source files

9
Database tables
P2P
Topology

multi-master, no central node

What it is

Inside Gravity Sync

Gravity Sync keeps a set of machines holding the same project tree without putting anything in charge. Each node runs its own Postgres and its own HTTP and WebSocket endpoint, watches a directory, and replicates file metadata and change logs peer to peer with whichever other nodes it is told about. There is no coordinator to lose.

The interesting parts are the failure cases. A peer that disconnects accumulates a pending-change queue and drains it on reconnect. A peer running an older schema — missing a table or a column — degrades gracefully rather than refusing to speak, and migrations propagate between peers rather than needing a synchronised deploy.

Its file tracking is borrowed, and openly so — the schema describes it as hash-based sync like Conduit. That is a design lineage rather than a dependency: the two share an idea about identifying files by content, and no code at all.

It is a prototype, and we would rather call it that than dress it up — complete enough to run, documented and containerised, but a working model of the idea rather than a product. The tests are not written, and nothing in production depends on it.

Built with

  • Node.js 18+ (ESM)
  • Express 4
  • Socket.IO 4
  • PostgreSQL 13+
  • chokidar
  • Podman

Capabilities

What it actually does.

01

Multi-master, no coordinator

Every node is a peer with its own database. Replication is direct between nodes over Socket.IO; there is nothing in the middle to be a single point of failure.

02

Survives disconnection

Pending-change queues accumulate while a peer is unreachable and propagate when it returns.

03

Selective sync

Each node declares which projects it owns and replicates only those, so a small machine need not carry everything.

04

Schema-mismatch tolerance

Peers on divergent schemas keep talking instead of failing, and migrations propagate between them rather than requiring a coordinated deploy.

05

Live event bus

Real-time broadcast of file changes to subscribed clients, with recent history replayed in the welcome frame so a late subscriber is not blind.

06

No build step

Pure ESM, runs directly under Node. Containerised with Podman for anyone who wants it that way.

Related

Where it sits.

Want something like this?

We build the same way for other people.