zlay#
an AT Protocol relay in zig. subscribes to every PDS on the network, verifies commit signatures, and serves the merged event stream to downstream consumers via com.atproto.sync.subscribeRepos.
live instance: zlay.waow.tech — metrics
design#
-
direct PDS crawl — the bootstrap relay (
bsky.network) is called once at startup for the host list vialistHosts, then all data flows directly from each PDS. -
optimistic signature validation — on signing key cache miss, the frame passes through immediately and the DID is queued for background resolution. the first commit from an unknown account is unvalidated; all subsequent commits are verified against the cached key. >99.9% cache hit rate after warmup.
-
inline collection index — indexes
(DID, collection)pairs directly in the event processing pipeline using RocksDB with two column families:rbcfor collection-to-DID lookups andcbrfor DID-to-collection cleanup. serveslistReposByCollectionfrom the relay process — no sidecar. the index design draws on fig's work on lightrail, which uses adjacent keys from CAR slices to enumerate collections. -
one OS thread per PDS — predictable memory, no garbage collector. ~2,750 threads is fine; most are blocked on websocket reads. thread stacks are set to 2 MB (zig's default is 16 MB).
endpoints#
| endpoint | method |
|---|---|
com.atproto.sync.subscribeRepos |
WebSocket |
com.atproto.sync.listRepos |
GET |
com.atproto.sync.getRepoStatus |
GET |
com.atproto.sync.getLatestCommit |
GET |
com.atproto.sync.listReposByCollection |
GET |
com.atproto.sync.listHosts |
GET |
com.atproto.sync.getHostStatus |
GET |
com.atproto.sync.requestCrawl |
POST |
dependencies#
| dependency | purpose |
|---|---|
| zat | AT Protocol primitives (CBOR, CAR, signatures, DID resolution) |
| websocket.zig | WebSocket client/server |
| pg.zig | PostgreSQL driver |
| rocksdb-zig | RocksDB bindings |
build#
requires zig 0.15 and a C/C++ toolchain (for RocksDB).
zig build # build
zig build test # run tests
zig build -Doptimize=ReleaseSafe # release build
configuration#
| variable | default | description |
|---|---|---|
RELAY_PORT |
3000 |
WebSocket firehose port |
RELAY_HTTP_PORT |
3001 |
HTTP API port |
RELAY_UPSTREAM |
bsky.network |
bootstrap relay for initial host list |
RELAY_DATA_DIR |
data/events |
event log storage |
RELAY_RETENTION_HOURS |
72 |
event retention window |
COLLECTION_INDEX_DIR |
data/collection-index |
RocksDB collection index path |
DATABASE_URL |
— | PostgreSQL connection string |
RELAY_ADMIN_PASSWORD |
— | bearer token for admin endpoints |
see docs/deployment.md for production deployment and docs/backfill.md for collection index backfill.
numbers#
| metric | value |
|---|---|
| connected PDS hosts | ~2,750 |
| memory | ~2.9 GiB |
| throughput | ~600 events/sec typical |