Real-time replicator for SpacetimeDB, inspired by Litestream.
Universe watches a SpacetimeDB data directory (commit logs, snapshots, module logs) and continuously streams new bytes to a remote receiver over TCP. On reconnection, the receiver reports its current offsets and the sender resumes from those points — no data is re-sent unnecessarily.
go install github.com/kidandcat/universe@latestOr build from source:
git clone https://github.com/kidandcat/universe.git
cd universe
go build -o universe .Start the receiver first. It listens on a TCP port and writes incoming data to a local mirror directory:
universe receive --port 9876 --dir /data/spacetime-replicaPoint the sender at your SpacetimeDB data directory and the receiver's address:
# Watch for new changes only
universe send --dir ~/.local/share/spacetime/data --to replica.example.com:9876
# Full sync first, then watch
universe send --dir ~/.local/share/spacetime/data --to replica.example.com:9876 --initial-syncThe --initial-sync flag walks the entire data directory and sends all existing bytes before switching to watch mode. Use it on the first run or when setting up a new replica.
┌─────────────────────┐ TCP ┌─────────────────────┐
│ SpacetimeDB Host │ ──────────────> │ Replica Host │
│ │ │ │
│ clog/*.stdb.log │ framed stream │ mirror/clog/... │
│ clog/*.stdb.ofs │ with CRC32 │ mirror/snapshots/ │
│ snapshots/... │ <────────────── │ mirror/module_logs/│
│ module_logs/... │ offset ACKs │ │
└─────────────────────┘ └─────────────────────┘
- Connect: Sender dials the receiver. Receiver sends an ACK with its current byte offsets per file.
- Initial sync (optional): Sender walks the data directory and sends all bytes from each file, starting from the receiver's last known offset.
- Watch: Sender uses
fsnotifyto watch for file changes (writes, creates). New bytes are read and sent as frames. - Frames: Each frame contains
[magic 4B][path len 2B][path][offset 8B][data len 4B][crc32 4B][data]. CRC32 ensures integrity. - ACKs: Receiver periodically sends ACK messages with its confirmed offsets. On reconnection, the sender resumes from these offsets.
Universe replicates the following files from a SpacetimeDB data directory:
data/
├── replicas/<id>/
│ ├── clog/
│ │ ├── *.stdb.log # Commit log (BSATN-encoded transactions)
│ │ └── *.stdb.ofs # Offset index for random access
│ ├── snapshots/
│ │ └── *.snapshot_dir/
│ │ ├── *.snapshot_bsatn
│ │ └── objects/<hash>
│ └── module_logs/
│ └── YYYY-MM-DD.log
├── control-db/
└── program-bytes/
| Flag | Default | Description |
|---|---|---|
--dir |
(required) | SpacetimeDB data directory (sender) or mirror directory (receiver) |
--to |
(required) | Receiver address as host:port (sender only) |
--port |
9876 |
TCP port to listen on (receiver only) |
--initial-sync |
false |
Send all existing data before watching (sender only) |
MIT