···11+# zlay
22+33+an [AT Protocol](https://atproto.com/) relay in zig. crawls PDS hosts directly and rebroadcasts their firehose as a single aggregated stream.
44+55+**live instance**: [zlay.waow.tech](https://zlay.waow.tech/_health) — [metrics dashboard](https://zlay-metrics.waow.tech)
66+77+## what it does
88+99+a relay subscribes to every PDS on the network, verifies commit signatures, and serves the merged event stream to downstream consumers via `com.atproto.sync.subscribeRepos`. it also maintains a collection index for `com.atproto.sync.listReposByCollection`.
1010+1111+## design
1212+1313+- **direct PDS crawl** — no fan-out relay in between. the bootstrap relay (bsky.network) is called once at startup for the host list, then all data flows from each PDS.
1414+- **optimistic validation** — on signing key cache miss, frames pass through immediately and the DID is queued for background resolution. >99.9% cache hit rate after warmup.
1515+- **inline collection index** — RocksDB with two column families for bidirectional `(DID, collection)` lookups. no sidecar process.
1616+- **one thread per PDS** — predictable memory, no GC. ~2,750 threads is fine; most are blocked on websocket reads.
1717+1818+## dependencies
1919+2020+| dependency | purpose |
2121+|---|---|
2222+| [zat](https://tangled.org/zzstoatzz.io/zat) | AT Protocol primitives (CBOR, CAR, signatures, DID resolution) |
2323+| [websocket.zig](https://github.com/nicholasgasior/websocket.zig) | WebSocket client/server |
2424+| [pg.zig](https://github.com/karlseguin/pg.zig) | PostgreSQL driver |
2525+| [rocksdb-zig](https://github.com/Syndica/rocksdb-zig) | RocksDB bindings |
2626+2727+## endpoints
2828+2929+| endpoint | method |
3030+|---|---|
3131+| `com.atproto.sync.subscribeRepos` | WebSocket (port 3000) |
3232+| `com.atproto.sync.listRepos` | GET |
3333+| `com.atproto.sync.getRepoStatus` | GET |
3434+| `com.atproto.sync.getLatestCommit` | GET |
3535+| `com.atproto.sync.listReposByCollection` | GET |
3636+| `com.atproto.sync.listHosts` | GET |
3737+| `com.atproto.sync.requestCrawl` | POST |
3838+3939+## build
4040+4141+requires zig 0.15 and a C/C++ toolchain (for RocksDB).
4242+4343+```bash
4444+zig build # build
4545+zig build test # run tests
4646+zig build -Doptimize=ReleaseSafe # release build
4747+```
4848+4949+see [docs/deployment.md](docs/deployment.md) for production deployment and [docs/backfill.md](docs/backfill.md) for collection index backfill.
5050+5151+## numbers
5252+5353+| metric | value |
5454+|---|---|
5555+| code | ~6,000 lines |
5656+| connected PDS hosts | ~2,750 |
5757+| memory | ~2.9 GiB steady state |
5858+| throughput | ~600 events/sec typical |