SSyncropel Docs

Federation: pairing two instances

Set up record sync between two Syncropel instances by hand. Covers identity setup, creating sync pairs, cross-namespace sharing, and common problems.

There's a one-command way

spl federation pair add <peer-url> does everything below in one command. It finds the peer, sets up access on both sides, and lets spl sync use the pair automatically. Most people should follow the federation pairing guide instead. This page covers the manual setup.

Who this is for

You have two Syncropel instances (one on your laptop and one on a server, or two servers, or any combination), and you want records emitted on one to show up on the other. This guide walks you through the setup.

If you're trying to find peer instances you don't yet have URLs for, start with the federation discovery guide instead. If you want records to reach a peer that's offline, see the async federation guide.

How federation works

A sync pair is a one-way subscription to one thread. When you create a pair on instance B pointing at instance A for thread T, you are saying: "B keeps pulling changes for thread T from A." Records written on A in thread T appear on B.

Three things to keep in mind:

  • A pair points at the source. A pair on B pointing at A means records flow from A to B.
  • Two-way sync needs two pairs, one on each side.
  • Each pair covers one thread. Syncing five threads takes five pairs.

Records are signed when written and checked when received. Receiving the same record twice has no effect.

Prerequisites

  • spl installed on both instances. Verify with spl version.
  • Both instances reachable from each other over HTTP. If one is behind NAT or bound to 127.0.0.1, see the troubleshooting section.
  • Each instance has an identity configured. Run spl init once on a fresh install. It creates a key and a did:key:... identity in ~/.syncro/config.toml. If your config has no identity, run spl init --force once.

Walk-through: pair two local instances

As an example, run two instances on the same machine using different SYNCROPEL_HOME directories: instance A on port 9200, instance B on port 9250. The same commands apply when the instances are on different machines.

1. Start both instances

# Terminal 1: instance A
export SYNCROPEL_HOME=/tmp/spl-a
spl init --force
spl serve --port 9200 --host 0.0.0.0

# Terminal 2: instance B
export SYNCROPEL_HOME=/tmp/spl-b
spl init --force
spl serve --port 9250 --host 0.0.0.0

Pass --host 0.0.0.0 when you want the instance reachable from other machines or containers. The default --host 127.0.0.1 only accepts loopback connections.

2. Capture each instance's DID

export DID_A=$(curl -s http://localhost:9200/v1/identity | jq -r '.did')
export DID_B=$(curl -s http://localhost:9250/v1/identity | jq -r '.did')

3. Create a pair: propagate A → B

To send records from A to B, create the pair on B (since B will pull from A):

spl fleet sync add \
    --peer-url http://localhost:9200 \
    "$DID_A" th_federation_demo

Or via HTTP (useful when scripting):

curl -X POST http://localhost:9250/v1/sync/pairs \
    -H "content-type: application/json" \
    -d "{\"peer_did\":\"$DID_A\",\"peer_url\":\"http://localhost:9200\",\"thread_id\":\"th_federation_demo\"}"

The response includes a pair_id, which you use to check status, pause, and remove the pair.

4. Emit on A, observe on B

# On instance A
SYNCROPEL_HOME=/tmp/spl-a spl intend --thread th_federation_demo "hello from A"

# Wait a moment (it checks every 5 seconds by default)
sleep 6

# On instance B, query the thread
SYNCROPEL_HOME=/tmp/spl-b spl thread records th_federation_demo

You should see the record emitted on A.

5. Go bidirectional

To also propagate B → A, create a pair on A pointing at B:

SYNCROPEL_HOME=/tmp/spl-a spl fleet sync add \
    --peer-url http://localhost:9250 \
    "$DID_B" th_federation_demo

Now records emitted on either side appear on the other within a few seconds.

6. Inspect pair status

spl fleet sync list
spl fleet sync status <pair_id>

The state field shows one of:

  • starting: the pair was just created and hasn't checked yet
  • running: syncing, and the last check succeeded
  • paused: pair is paused via spl fleet sync pause <pair_id>
  • failing: the pair keeps retrying, waiting longer each time; last_error has the reason
  • stopped: pair has been removed

7. Check all your pairs at a glance

Once you have several pairs, spl status shows a Federation section with one line per pair: direction, peer, thread, records per minute, delay, and any error. It is the quickest way to see whether anything is wrong.

Federation (5 pairs: 3 running, 1 failing, 1 paused)
  abc12345  ← alice    thread:th_acme_ops   7 rec/min, lag 2s
  def45678  → bob      thread:th_acme_ops   4 rec/min, lag 0s
  345cdef0  ← carol    thread:th_archive    FAILING: CONNECT_REFUSED
  ...

For machine-readable access use spl status --json or query the endpoints directly:

  • GET /v1/sync/health: overall health, covering pairs by state, records received per hour and per minute, delivery delay across all pairs, the slowest and most error-prone pairs, and any active alerts.
  • GET /v1/sync/pairs/{id}/stats: one pair's current rate, delay, errors in the last hour, and totals.

Peer discovery: finding other instances without typing URLs

You don't have to enter every peer_did and peer_url by hand. spl fleet sync peers discover finds peers in four ways:

spl fleet sync peers discover                            # Try all methods
spl fleet sync peers discover --method mdns              # LAN broadcast
spl fleet sync peers discover --method did-web --domain alice.dev
spl fleet sync peers discover --method did-sync --namespace acme-corp
spl fleet sync peers discover --method static            # Peers from config

mDNS (LAN broadcast): on the same local network, instances can advertise themselves on _syncropel._tcp.local and find each other in under a second. Listening is on by default. Advertising is off by default; turn it on with [sync.discovery] mdns_broadcast = true in ~/.syncro/config.toml.

did:web resolution: if you know a peer's domain (e.g., alice.dev), Syncropel reads https://alice.dev/.well-known/did.json to find the peer's address. No directory service is needed. Publish your own with spl identity publish-did-web --domain alice.dev.

did:sync directory lookup: for peers registered in a shared directory (discovery.syncropel.com or your own), list the peers in a namespace and look up each one's address.

Static config: for isolated networks or debugging, list peers directly in ~/.syncro/config.toml.

Discovery never creates pairs for you. Review the list, then run spl fleet sync add <did> <thread> for each peer you want.

Pair error codes

When a pair is failing, last_error holds one of these codes:

CodeMeaningFix
CONNECT_REFUSEDPeer instance not reachableCheck peer is running; if cross-machine, make sure it's not bound only to 127.0.0.1
TIMEOUTPeer didn't respond in timeNetwork slow or peer overloaded
DNS_FAILUREpeer_url hostname doesn't resolveTypo in the URL, or DNS is unavailable
HTTP_4XXPeer rejected the requestCheck that the namespaces are registered, and check consent grants and signatures
HTTP_5XXError on the peerCheck the peer's logs
PARSE_ERRORPeer returned malformed JSONThe peers run incompatible versions, or the peer isn't an spl instance

Cross-namespace sharing

By default, records in one namespace are not visible to a peer in a different namespace, because consent blocks them. To grant cross-namespace consent, use spl consent grant on the source instance:

spl consent grant --to-namespace partner-team --hash-levels L0,L1,L2,L3

See the consent management guide for the full flow.

Troubleshooting

"My pair was created but no records propagate"

The most common cause is an instance bound to 127.0.0.1 while the pair points at a non-loopback host. Two signals to check:

  • The response to POST /v1/sync/pairs includes a warning field when this is detected.
  • spl doctor flags it:
! federation bind host      1 sync pair(s) configured but instance is bound
                            to 127.0.0.1. Remote peers cannot reach this
                            instance. Restart with
                            `spl serve --host 0.0.0.0 --daemon`.

Fix: restart the instance with --host 0.0.0.0.

"Instance rejects records with namespace X"

Error: NAMESPACE_REJECTED: ancestor 'X' is not Active in the registry.

Namespaces must be registered before records in them can be emitted:

spl namespace create X --description "..."

This is a deliberate safety default. Namespaces are never created implicitly.

"Pulls return zero records on a thread that should have some"

Check consent. If the source and target namespaces differ and there's no matching consent grant, records are filtered out silently. spl consent list on the source shows active grants.

What's next

On this page