ungovernable.tech

Field guide[ GUIDE ][ SECURE MESSAGING ][ CENSORSHIP CIRCUMVENTION ]

Running a Nostr Relay

Also Nostr relay guide, strfry guide, nostr relay operations.

A relay is a dumb, untrusted event store: it validates signatures, stores JSON, and serves filters over a WebSocket. Anyone can run one, and running one is how a person or a group stops depending on somebody else's relay policy, retention, and logs.

updated 2026-11-29 14 min read [ INTERMEDIATE ]
Contents

Companion notes: Nostr Deep Dive for the protocol, Nostr Key Custody and Recovery for keys, and Metadata Resistance for how Nostr compares to designs that hide who-talks-to-whom architecturally.

Summary

A Nostr relay accepts signed events from clients over WebSocket, verifies them, stores them, and serves them back to any client whose filters match. There is no federation handshake, no user accounts, and no admin approval at the protocol level — the relay's policy is whatever the operator configures. Running your own relay buys you three things: (1) retention control — your notes persist as long as you decide, not as long as a third party tolerates; (2) write policy — you decide whose events your server stores; (3) an inbox you control — with NIP-65 and kind 10050 relay lists you can publish, other users' clients know where to deliver mentions and gift-wrapped DMs to you.

It does not buy you anonymity. A relay sees the IP address of every client that connects, every subscription filter, and the plaintext of every event that is not NIP-17-gift-wrapped. Public notes, kind-3 follow lists, kind-10002 relay lists, and profile metadata are all published in cleartext to any relay you post to, and a relay operator can log all of it. The threat model section below spells out what running a relay hides, what it exposes, and where NIP-17 gift-wrapping and Tor change the picture.

This week's version anchors (checked 2026-11-09 from the repos directly): strfry is actively maintained (last push 2026-11-03, 737 stars, GPLv3, no tagged releases — track master), khatru's GitHub repo was archived by the owner on 2026-01-24 and development moved to the fiatjaf.com/nostr/khatru Go module, and nostr-rs-relay saw its last push 2026-05-22. khatru's archived-repo status is new information the site does not yet reflect.

What a relay does and does not do

Concern Handled by the protocol? Handled by running your own?
Signature validation Yes — every relay verifies before storing Same (you gain nothing here)
Content persistence No — relays may delete anything Yes — your retention policy rules
Censorship of your posts Per-relay, by policy Yes for writes you accept; no for reads elsewhere
Metadata (who talks to whom, when) No — NIP-17 gift-wraps help for DMs only No — your relay logs everyone else's metadata instead
IP privacy of your clients No No — you trade your IP exposure for visibility into others'
Spam resistance No — protocol has none Only what you configure (write policy, PoW, payment)
Discovery No — relays are not search engines Same

The key asymmetry: running a relay is an act of infrastructure sovereignty, not personal anonymity. If anything, the operator role concentrates metadata about other people. That is a responsibility, and in some jurisdictions a legal one (see attack surface below).

Choosing relay software

strfry (C++, single binary, LMDB)

The most widely deployed self-hosted relay for general-purpose use. Properties that matter operationally (from the README, verified 2026-11-09):

  • No external database — all data in LMDB on the local filesystem. Backup is a directory copy; migration is strfry export/import in JSONL, with a --fried precomputed-index format for fast re-import across DB schema versions.
  • NIPs supported: 1, 2, 4, 9, 11, 28, 40, 42, 45, 70, 77 — including NIP-42 AUTH (client authentication) and NIP-11 (relay information document).
  • Durable writes: an OK is returned to the client only after the event is committed to LMDB, so a crash never acknowledges an event it then loses.
  • Negentropy set reconciliation (strfry sync) — a relay can sync its full DB (or a filter subset, e.g. one author's events) with another relay in both directions, transferring only the difference. This is the mechanism behind relay-to-relay backup and the strfry router mode.
  • Prometheus metrics endpoint for monitoring messages by verb and events by kind.
  • Hot config reload and zero-downtime restarts.
  • Write policy plugins: policy logic lives outside the core. strfry feeds each incoming event (plus client IP, source type, and authed pubkey) to a plugin over stdin; the plugin answers accept, reject, or shadowReject in JSONL. Plugins can be written in any language that reads lines and prints JSON — the docs show a Node whitelist example, and Nostrify ships a Deno-based policy pipeline (hellthread limits, anti-duplication, pubkey bans).
  • Default bind is localhost:7777 — safe by default; production needs relay.bind = "0.0.0.0" or a reverse proxy.

Build: a C++20 compiler plus libssl-dev zlib1g-dev liblmdb-dev libflatbuffers-dev libsecp256k1-dev libzstd-dev, then make setup-golpe && make -j4. FreeBSD and macOS builds are documented too.

khatru (Go framework — note the archive)

khatru is not a relay binary; it is a Go library for writing custom relays: you wire in your own storage (or plug eventstore's SQLite/Postgres backends), your own acceptance policies (RejectEvent, RejectFilter hooks), custom AUTH handlers, and arbitrary HTTP handlers alongside the WebSocket endpoint. policies.ApplySaneDefaults(relay) gives a sane baseline; built-ins include ValidateKind, PreventLargeTags, and NoComplexFilters.

Critical currency note: the github.com/fiatjaf/khatru repo was archived on 2026-01-24 and is read-only. Development continues as the fiatjaf.com/nostr/khatru Go module with a slightly different API. Tutorials pointing at the GitHub repo import path still work via Go module proxy redirects, but new code should import the new module path. Anything referencing khatru as an actively-developed GitHub repo is stale.

Other options in one line

  • nostr-rs-relay (Rust, SQLite, single binary): last push 2026-05-22; minimal — no built-in auth or plugin system. Good for a low-resource personal relay where you do not need policy flexibility.
  • nostream (TypeScript): feature-rich, higher resource use.
  • mostr / Satellite / others: niche; check liveness before adopting (the ecosystem has dead projects).
If you want Use
General-purpose public or group relay with policy plugins strfry
A relay embedded in your own application khatru (new module path)
Minimal personal archive relay on a small VPS nostr-rs-relay

Setup walkthrough (strfry)

A minimal production deployment on a Linux VPS:

  1. Build and install per the README (above). Put the binary somewhere persistent, e.g. /opt/strfry/.
  2. Config: strfry looks for --config, then $STRFRY_CONFIG, then /etc/strfry.conf, then ./strfry.conf. Only db is mandatory; everything else defaults sensibly. The parameters you will actually touch: - relay.bind — leave 127.0.0.1 behind a reverse proxy, or 0.0.0.0 for direct exposure. - relay.port — default 7777. - relay.auth.serviceUrl — the public wss:// URL; required for NIP-42 AUTH to work. - relay.info.* — NIP-11 metadata: name, description, contact, pubkey. This is public: it is how clients and humans evaluate your relay's policy. Fill it in honestly. - Event limits: events.maxEventSize (default 65536 bytes is a sane cap), future/past created_at rejection windows, tag count and size caps. These are your first line of defense against junk.
  3. TLS: terminate TLS in nginx/Caddy and proxy to 127.0.0.1:7777. Clients connect to wss://your-relay.example.com.
  4. Write policy: start permissive, watch the Prometheus counters, then add a plugin once you know your abuse pattern. A whitelist plugin (accept only your own pubkey) turns the relay into a personal outbox; a paid-access plugin via NIP-42 auth or a Lightning payment check turns it into a paid relay; a shadowReject answer silently drops spam without telling the sender (useful, but a silent-failure mode users cannot diagnose).
  5. Backups: strfry export > backup.jsonl on a cron, or filesystem snapshots of the LMDB directory. strfry sync wss://backup-relay --dir both gives continuous relay-to-relay redundancy via negentropy — this is the cheapest real durability Nostr offers.
  6. Monitor: the Prometheus endpoint gives per-verb message counts and per-kind event counts; alert on sudden kind-1 volume spikes (spam waves) and on connection count jumps.

For a khatru custom relay, the shape is: create the relay, register StoreEvent/QueryEvents/DeleteEvent handlers (three lines each with an eventstore backend), append rejection policies, and serve. The entire relay fits in ~40 lines of Go; the effort goes into the policy, not the plumbing.

The outbox model: NIP-65 and kind 10050

This is the piece that turns "I run a relay" into "other people can reach me on my terms".

NIP-65 (relay list metadata) defines replaceable kind 10002: a list of r tags with relay URLs, each marked read, write, or both. The convention:

  • Clients publish your events to your write relays.
  • Clients fetch your events from your write relays.
  • Clients fetch events mentioning you from your read relays — so the relays you mark read are where replies find you.
  • Guidance: keep the list small (2–4 relays per category) and spread the kind-10002 event itself widely so clients can discover it.

The operational consequence: if your write relay is your own, your posts land on infrastructure you control first, and everything else is replication. strfry router can then stream your events outward to public relays automatically — your server becomes the origin, public relays become caches.

kind 10050 (NIP-17 DM inbox) is a separate, smaller list: the relays where you accept gift-wrapped direct messages. NIP-17 requires clients to publish gift wraps only to the recipient's kind-10050 relays. Keeping this list at 1–3 relays is deliberate: your DM inbox is your metadata chokepoint, and a small list means you can choose relays whose logging and AUTH policies you trust (ideally your own, or one that enforces NIP-42-gated reads of kind 1059).

The two lists are separable on purpose: you may broadcast publicly from a big-permissive relay while receiving DMs on a tiny authenticated one.

Threat model: what relays see, leak, and can do

This is the part the "Nostr is censorship-resistant" pitch omits. Everything here is grounded in the NIP-17/NIP-59/NIP-65 specifications and relay-software documentation.

What a relay operator sees about you

  • Your IP address on every connection. WebSocket TLS hides the payload from network observers, not from the relay.
  • Every subscription filter you issue: authors, kinds, search terms, since/until. Subscription patterns reveal interest even when content is encrypted.
  • Every plaintext event you post: kind 0 profile metadata, kind 1 notes, kind 3 follow lists, kind 10002 relay lists, long-form articles, zap receipts. All are public by design; the relay stores and can log them forever.
  • Correlation across your relay usage: the same pubkey connecting from the same IP to post and to read builds a clean activity log with no Tor in the path.

What NIP-17 gift-wrapping hides — and what it does not

NIP-17 + NIP-59 is a three-layer envelope: unsigned rumor → kind-13 seal (encrypted to the recipient, signed by the sender) → kind-1059 gift wrap (encrypted to the recipient, signed by a random ephemeral key). Per the spec:

  • The relay sees only a kind-1059 event from a random key with a single p tag naming the recipient. The sender is hidden; the content is hidden; created_at is randomized up to two days into the past to frustrate timing correlation.
  • The recipient's pubkey is still on every gift wrap in the p tag — this is how the relay (and any client) knows to attempt decryption. Recipient identity is not hidden from relays.
  • Spam protection must not use pubkey reputation: since wrappers use random keys, NIP-17 explicitly warns that naive relays are spam targets and points at NIP-59's proof-of-work approach (NIP-13).
  • Relays should serve kind-1059 events only to clients authenticated (NIP-42) as the p-tagged user — "Relays SHOULD protect message metadata by only serving kind:1059 events to users p-tagged on the event". If your inbox relay does not enforce AUTH-gated reads, anyone can download your entire gift-wrapped DM inbox and confirm which events are addressed to you. When you pick a kind-10050 relay, test this: connect unauthenticated and try to fetch kind 1059.
  • Seals and gift wraps carry no tags other than the routing p tag (plus optional expiration), so the envelope leaks little beyond recipient and timing noise. But volume and rhythm remain: a relay watching one recipient's inbox sees message frequency and sizes.

What running your own relay changes

  • You stop leaking your reads/writes to third-party relay operators — but your clients' IPs now hit your server, whose logs you must protect. A seized relay server is a complete archive of everything it stored, plus connection logs if enabled.
  • Your relay is a named, geolocatable, jurisdictionally-anchored target. The wss:// URL in your kind-10002 list points at a real host. If you are the threat model, the relay must live outside your jurisdiction, or behind Tor.
  • Tor exposure: relays can be served as onion services; clients that route relay traffic over Tor (many support SOCKS proxies) break the IP↔pubkey link at the relay. The cost is latency and the operational burden of an onion service.
  • Legal exposure of the operator: a public relay stores whatever strangers post. Depending on jurisdiction, that can include content you did not choose and cannot review at scale. Write policy is not just anti-spam — it is the operator's main legal shield. Restricted-write relays (whitelists, paid) exist for this reason; NIP-11's restricted_writes flag exists so clients can warn users before they attempt to post.
  • Relay censorship is still real: your own relay guarantees storage of what you post to it, but it cannot force other relays to accept your events, and it cannot stop clients from refusing to display you. Censorship resistance in Nostr is "no single point can silence you", not "no one can ignore you".

Relay-side censorship and the NIP-17 recipient tag

The concern is "relay censorship and the NIP-17 recipient tag". The concrete mechanics:

  • A relay can refuse to store your kind-10002 or kind-10050 lists (write policy), breaking discovery of your outbox — the mitigation is spreading those lists to many relays, which both NIP-65 and NIP-17 instruct clients to do.
  • A relay hosting your DM inbox can silently drop kind-1059 events addressed to you (censorship of receipt). You cannot detect this directly — no read receipts exist. Mitigations: run your own inbox relay (the sovereign option), or use two independent inbox relays and compare delivery.
  • The p tag on every gift wrap means an adversarial inbox relay knows who receives each message even though the sender is hidden. A malicious relay can build a per-recipient social-contact graph from gift-wrap traffic alone — frequency, volume, and (with AUTH-gated reads absent) the full set of senders by observing which keys later appear in seal decryptions leaked by buggy clients. The protocol cannot fix this; inbox-relay choice is a trust decision, exactly like choosing a Signal server is not possible and choosing an email provider is.

NIP-42 AUTH: what it does and does not give you

NIP-42 is challenge-response: the relay sends a challenge, the client signs an ephemeral kind-22242 event including it, and the relay then knows the socket belongs to a given pubkey. Uses: gating reads of restricted events (gift-wrapped DMs), paid access, whitelist writes. What it does not do: it is not anonymity (you just told the relay which pubkey you are), and it is not a strong identity system (a client can authenticate with a throwaway key). Its privacy value is strictly "the relay only shows my DMs to me" — which is why NIP-17 marks it the mechanism relays SHOULD use for kind-1059 read protection.

Relay software has had auth bugs too

NIP-42 AUTH is easy to get subtly wrong. Citrine 3.1.1 (11 September 2026) fixed a bypass in which kind 22242 AUTH events were added to a connection without verifying their signature, and in the same release scoped REQ subscription ids per connection (so one socket could no longer clobber another's subscription) and fixed NIP-45 COUNT handling (release notes). Treat relay and signer releases as security-relevant, and test your own relay by presenting an AUTH event with a bad signature.

Trade-offs

Strengths of running your own relay

  • Retention is your policy; no third party can expire your history.
  • Write policy is your decision — a personal relay that accepts only your pubkey is a self-sovereign archive.
  • NIP-65/10050 lists pointing at your relay make you reachable on infrastructure you control.
  • Relay-to-relay negentropy sync gives cheap redundancy without trusting a backup provider.
  • Contributes to network diversity: more independent relays mean fewer single points of policy.

Limitations and honest costs

  • No anonymity gain — the relay role concentrates metadata; it does not shield yours.
  • Operation is real work: updates (strfry tracks master; no release tags), disk growth (LMDB stores everything you accept), abuse handling, and — for public relays — possible legal attention to stored content.
  • khatru's repo is archived (2026-01-24); framework users must track the new Go module path and accept occasional API breaks.
  • Discovery still depends on others: your relay does not make you findable; follow lists and relay-list spread do.
  • kind-1059 read protection depends on relay enforcement of NIP-42; many public relays do not enforce it, leaving DM inbox metadata readable.

Attack surface

Attack / failure Effect Mitigation
Relay seizure Full event archive + logs in adversary hands Keep logs off by default; jurisdiction choice; Tor onion service; encrypted backups
Unauthenticated kind-1059 fetch Strangers harvest recipients' DM inboxes Choose inbox relays enforcing NIP-42; test yours
Relay drops your events silently Undeliverable mentions/DMs Multi-relay kind-10002/10050 lists; own inbox relay
Spam flood via random wrapper keys Storage/log DoS on inbox relay NIP-13 PoW requirements; rate limits; paid writes
Plugin/plugin-language RCE Server compromise via write-policy plugin Run plugins least-privilege; pin dependencies; sandbox (Deno)
Subscriber-pattern analysis Interest graph from filters despite E2EE DMs Tor for client connections; rotate subscriptions; split read/write relays
NIP-11 metadata abuse Your relay info used for phishing Keep relay.info accurate; monitor clones
Legal takedown of public relay Relay offline / data handed over Restricted writes; jurisdiction; export + strfry sync to secondary relay

Evidence

Claim Source Date verified
strfry stores all data in LMDB, durable writes before OK, NIP list 1,2,4,9,11,28,40,42,45,70,77, negentropy sync, plugin architecture, default localhost:7777 strfry README 2026-11-09
strfry last push 2026-11-03; 737 stars; GPLv3; no tagged releases GitHub API repos/hoytech/strfry 2026-11-09
khatru repo archived by owner 2026-01-24, read-only; successor is fiatjaf.com/nostr/khatru module khatru repo banner 2026-11-09
nostr-rs-relay last push 2026-05-22; 723 stars GitHub API repos/scsibug/nostr-rs-relay 2026-11-09
NIP-65: kind 10002, r tags with read/write markers, clients use write relays for author's events and read relays for mentions, 2–4 relays per category NIP-65 2026-11-09
NIP-17: kind 10050 DM inbox list (1–3 relays); clients publish gift wraps only to recipient's 10050 relays; relays SHOULD gate kind-1059 reads via NIP-42; created_at randomized ≤2 days; spam warning re random wrapper keys NIP-17 2026-11-09
NIP-59: gift wrap carries recipient p tag; seal signed by sender, wrap signed by ephemeral key NIP-59 2026-11-09
NIP-11: relay information document fields incl. limitation block (auth_required, payment_required, restricted_writes, min_pow_difficulty) NIP-11 2026-11-09
NIP-42: AUTH challenge-response via signed ephemeral event; used to gate restricted reads and writes NIP-42 2026-11-09

Primary Sources

Also in Censorship Circumvention

Page history

Updated
2026-11-29
Origin
Compiled from the ungovernable.tech research notes.
Improve this page
Suggest an edit — issues and pull requests are welcome.