Skip to content

Relay Server

DoDon’t
Accept iroh connections (QUIC)Store data long-term
Noise handshakeDecrypt payloads
Route messages by group_idKnow what’s in blobs
Buffer for offline devices (temp)Require accounts
Assign monotonic cursorsProcess application logic
Clean up expired blobs
-- SQLite with WAL mode for concurrent access
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
PRAGMA busy_timeout=5000;
-- Cursor sequence per group
CREATE TABLE group_cursors (
group_id BLOB PRIMARY KEY,
next_cursor INTEGER NOT NULL DEFAULT 1
);
-- Temporary blob buffer
CREATE TABLE blobs (
blob_id BLOB PRIMARY KEY,
group_id BLOB NOT NULL,
cursor INTEGER NOT NULL,
sender_id BLOB NOT NULL,
payload BLOB NOT NULL, -- Still encrypted
timestamp INTEGER,
expires_at INTEGER NOT NULL, -- Auto-delete time
created_at INTEGER,
UNIQUE(group_id, cursor)
);
-- Track delivery status
CREATE TABLE deliveries (
blob_id BLOB,
device_id BLOB,
delivered_at INTEGER,
PRIMARY KEY (blob_id, device_id)
);
-- Indexes
CREATE INDEX idx_blobs_group_cursor ON blobs(group_id, cursor);
CREATE INDEX idx_blobs_expires ON blobs(expires_at);

On Connection (HELLO):

  1. Complete Noise handshake
  2. Validate HELLO message
  3. Register device for group
  4. Send WELCOME with max_cursor, pending_count
  5. Send NOTIFY for each pending blob

On PUSH:

  1. Begin transaction
  2. Increment cursor atomically:
    INSERT INTO group_cursors (group_id, next_cursor) VALUES (?, 1)
    ON CONFLICT(group_id) DO UPDATE SET next_cursor = next_cursor + 1
    RETURNING next_cursor - 1 AS assigned_cursor;
  3. Store blob with cursor and TTL
  4. Commit
  5. Send PUSH_ACK to sender
  6. Send NOTIFY to all other online devices in group

On PULL:

  1. Query blobs where cursor > after_cursor
  2. Order by cursor ASC
  3. Limit results
  4. Return blobs with has_more flag
  5. Mark as delivered for this device

On DELETE:

  1. Check if all devices have ACKed
  2. If yes, delete blob
  3. If no, mark pending delete

Cleanup (hourly):

  1. Delete expired blobs (past TTL)
  2. Delete blobs where all devices ACKed
  3. Run PRAGMA incremental_vacuum
ResourceLimitWindow
Connections per IP10Concurrent
Messages per device100Per minute
Blob size1 MBPer blob
Buffer per group100 MBTotal
Default TTL7 daysPer blob

GET /health

{
"status": "ok",
"version": "1.0.0",
"connections": 42,
"groups": 15,
"blobs_buffered": 127,
"uptime_seconds": 86400
}

GET /metrics (Prometheus format)

sync_relay_connections_total 1567
sync_relay_connections_active 42
sync_relay_blobs_buffered 127
sync_relay_blobs_delivered 45892
sync_relay_bytes_transferred 157286400