A Nostr Relay is a simple, stateless server that receives, stores, and broadcasts messages, called events, for users of the decentralized Nostr protocol. Unlike servers in centralized platforms, relays do not authenticate users, control identities, or enforce a global state; they are dumb pipes that accept valid events from anyone and make them available to subscribers. Users run a Nostr client (like an app) that connects to multiple relays of their choosing to publish notes and receive updates from others, creating a resilient and censorship-resistant network where no single entity has control.
Nostr Relay
What is a Nostr Relay?
A Nostr Relay is a fundamental infrastructure component of the Nostr protocol, a decentralized social networking framework.
The architecture is intentionally minimalistic. Relays communicate with clients via a standardized WebSocket or HTTP-based protocol, exchanging JSON-formatted events. Each event is cryptographically signed by a user's private key, allowing anyone to verify its authenticity and origin. Key functions of a relay include: - Validating event signatures and structure - Storing events temporarily or permanently - Allowing clients to query for events using filters (e.g., by author, time, or content) - Forwarding events to other connected clients in real-time. This design enables users to maintain their social graph and data across a diffuse network of independent servers.
Running a relay is a public service, similar to running a Bitcoin node, but it can also be a private or paid service. Public relays foster network liquidity, while private relays allow individuals or communities to control their data flow and ensure availability. Since there is no inherent economic incentive, relay operation is often altruistic or supported by donations. The decentralized nature means if one relay goes offline or censors a user, the client can simply connect to others, ensuring data redundancy and anti-fragility. This makes Nostr fundamentally different from federated protocols like ActivityPub (used by Mastodon), which rely on inter-dependent servers.
For developers and users, the relay model offers significant flexibility. A client can aggregate data from dozens of relays to get a complete view, or use specialized relays for specific content types (e.g., one for global chat, another for long-form articles). The protocol's simplicity has led to a vibrant ecosystem of implementations in various programming languages, making it easy to deploy a custom relay. The ultimate power resides with the user, who controls their private keys, chooses their relays, and owns their social data—a core tenet of the "self-sovereign" social web that Nostr enables.
How a Nostr Relay Works
A technical breakdown of the fundamental server component in the Nostr protocol, detailing its role in receiving, storing, and broadcasting decentralized messages.
A Nostr relay is a simple, stateless server that receives, temporarily stores, and broadcasts events—the fundamental data units in the Nostr protocol—between clients. Unlike servers in federated or blockchain-based systems, relays are intentionally minimal and interchangeable; they perform no authentication, impose no global rules (unless operated privately), and do not communicate with each other. A client's resilience and access to the network depend on its connection to multiple, independent relays, creating a redundant and censorship-resistant mesh. The primary interaction is via a WebSocket connection, where clients send EVENT and REQ messages to publish and subscribe to data.
The relay's core function is event validation and storage. Upon receiving an event—which is a signed JSON object containing content, metadata, and a cryptographic signature—the relay performs basic checks. These typically verify the event's id (a SHA256 hash of its contents), the validity of the cryptographic sig against the author's public key, and adherence to the Nostr protocol specification (NIPs). Optionally, a relay operator may enforce additional rules, such as rate-limiting, content filtering, or requiring payment (as defined in NIP-05 or NIP-65). Valid events are stored in the relay's local database and immediately broadcast to all connected clients subscribed to relevant filters.
Client interaction is governed by subscription filters. A client opens a subscription by sending a REQ message with an array of filter objects (e.g., {"authors": ["pubkey..."], "kinds": [1]}) to request text notes from specific users. The relay then returns all matching historical events from its database and pushes new, matching events in real-time. This publish-subscribe model is highly efficient, as a single client connection can manage dozens of active subscriptions. Since relays are independent, a client must connect to several to gather a complete view of the network, a design that prevents any single point of failure or control.
Operationally, relays can be public, private, or paid. A public relay accepts connections and events from anyone, often becoming a large, general-purpose hub. A private relay may restrict access to a specific community or set of public keys, acting as a gated server. Paid relays, enabled by mechanisms like NIP-05 (Lightning payments), require a small fee to publish or read, which helps mitigate spam and funds infrastructure. The relay software itself is typically open-source, with implementations like nostr-rs-relay (Rust) or strfry (C++) providing the core functionality for operators to deploy.
The decentralized architecture means data persistence is not guaranteed. A relay operator can choose to delete old events, go offline, or purge data at any time. Therefore, Nostr clients and users are responsible for their own data durability by publishing events to multiple relays and using personal Nostr clients that archive their own data. This model shifts the burden of permanence from the network infrastructure to the edges, aligning with Nostr's philosophy of minimal trust. The relay's role is purely one of voluntary, temporary hosting and real-time message passing within a global, permissionless ecosystem.
Key Features of a Nostr Relay
A Nostr relay is a simple, stateless server that forms the backbone of the decentralized social networking protocol, responsible for storing and distributing user events.
Stateless & Simple Protocol
Relays implement the Nostr protocol using a simple, HTTP-based JSON API. They are inherently stateless regarding user identity, as authentication is handled cryptographically via public keys and signatures. This design allows for easy deployment and horizontal scaling.
- Core Operations: Primarily
EVENT(publish) andREQ(subscribe/query) messages. - No Consensus: Relays do not need to agree on data; they independently accept and serve events based on their own rules.
Event Storage & Propagation
The primary function is to durably store Nostr events (structured JSON objects) and propagate them to subscribed clients. Events are immutable once published and indexed by their event ID (a SHA256 hash).
- Persistence: Relays maintain a local database (e.g., SQLite, PostgreSQL) of events.
- Pub/Sub Model: Clients open WebSocket connections and use filters to subscribe to specific events (e.g., from certain authors, with specific tags).
Decentralized & Permissionless Operation
Anyone can run a relay, and users can connect to multiple relays simultaneously. This creates a decentralized, fault-tolerant network where no single entity controls the flow of information.
- Redundancy: Users publish events to multiple relays to ensure availability.
- Censorship Resistance: A user cannot be globally deplatformed, as they can always publish to other relays.
- Relay Lists: Client apps often use NIP-65 (Relay List Metadata) to discover and manage a user's preferred relay set.
Filter-Based Query System
Clients retrieve data by sending filter objects to relays via REQ requests. Filters specify criteria for the events a client wants to receive, enabling efficient data fetching.
- Common Filters: Include
authors(public keys),kinds(event types),since/until(timestamps), and#e/#ptags. - Example Filter:
{"authors": ["pubkey1"], "kinds": [1], "since": 1672531200}fetches text notes (kind 1) from a specific author after a given timestamp.
Admission Control & Moderation
Relay operators enforce local policy through admission control, deciding which events to accept, store, and broadcast. This is a key point of decentralization, allowing for diverse community standards.
- Methods: Can include whitelists/blacklists of public keys, rate limiting, content filtering (e.g., for spam), and payment requirements (e.g., via NIP-57 Lightning zaps).
- NIP-56: Standardizes reporting of harmful content between relays.
NIP Extensibility
Relay functionality is extended through Nostr Implementation Possibilities (NIPs), which are standardized protocol extensions. A relay's supported features are often advertised in its NIP-11 metadata.
- Core NIPs: NIP-01 (Base protocol), NIP-05 (Human-readable identifiers).
- Advanced Features: NIP-04 (Encrypted Direct Messages), NIP-09 (Event Deletion), NIP-78 (Personalized Application Data).
- Interoperability: Clients and relays negotiate capabilities based on supported NIPs.
Types of Nostr Relays
Nostr relays are servers that store and forward events. They can be categorized by their operational model, access rules, and specialized functions.
Public Relays
Open relays that accept connections and events from any client. They form the backbone of the public Nostr network.
- Purpose: Maximize network reach and censorship resistance.
- Examples:
wss://relay.damus.io,wss://nostr.wine - Consideration: Performance and data retention policies vary widely.
Private Relays
Restricted relays that require authentication, such as a NIP-42 token or payment. They control access to manage load, spam, or create exclusive communities.
- Purpose: Resource management, spam prevention, monetization.
- Implementation: Often use NIP-42 (Authentication) for access control.
Paid Relays
A subset of private relays that require payment, typically in Bitcoin via Lightning Network (LNURL or NIP-57), to publish or read events.
- Purpose: Sustainable operation, spam deterrence, and premium services.
- Mechanism: Payment grants a time-limited or capacity-based publishing token.
Write-Relays & Read-Relays
Relays specialized for a single function, often used in client configuration for performance and privacy.
- Write-Relay: A trusted relay where a client publishes its events. Ensures data persistence.
- Read-Relay: A relay queried for fetching events, often a large, public aggregation point. Clients may use many read-relays.
Community/Subject Relays
Relays that filter content to a specific topic, community, or application, acting as a curated feed.
- Purpose: Create focused environments (e.g., only chess games, specific artist notes).
- Mechanism: May reject events not matching defined criteria (NIP-01 tags, kinds).
Personal/Ephemeral Relays
Lightweight relays, often self-hosted, for personal use or temporary data exchange. This includes nostr-rs-relay or strfry instances.
- Purpose: Data sovereignty, testing, or private group communication.
- Characteristic: May have limited capacity, no public discovery, and can be shut down easily.
The Client-Relay Relationship
The fundamental interaction model that defines how decentralized applications (clients) communicate with the network's infrastructure (relays) in the Nostr protocol.
In the Nostr (Notes and Other Stuff Transmitted by Relays) protocol, the client-relay relationship is a simple, stateless, and permissionless connection model. A client (any software that creates or requests data, like a social media app or a wallet) connects to one or more independent relays (servers that store and forward messages). This relationship is not exclusive; a single client typically connects to multiple relays for redundancy and data access, while a single relay serves countless clients. The core operations are publishing events (e.g., posts, reactions) to relays and subscribing to filters to receive relevant events from them.
This architecture creates a decentralized and censorship-resistant network. There is no central server or mandatory relay. If one relay rejects a user's content or goes offline, the client can simply connect to others. The relationship is standardized through open protocols—primarily using WebSockets—where clients send EVENT and REQ messages, and relays respond with EVENT, EOSE, and NOTICE messages. This ensures interoperability between any compliant client and relay software, such as nostr-rs-relay or Damus.
The economic and operational model of this relationship is flexible. Relay operators may choose to run public relays freely, private relays for specific communities, or paid relays that require authentication (NIP-42) or payment (e.g., via NIP-57 Lightning zaps) for service. Clients must strategically manage their relay connections, balancing factors like latency, reliability, cost, and the specific data filtering each relay supports (NIP-01). This design places control with the user's client software, which is responsible for aggregating the user's social graph and content from the disparate relay network.
Technical Specifications (NIPs)
Nostr's core protocol is minimal. Its functionality is extended through Nostr Implementation Possibilities (NIPs), which are community-authored standards for features like direct messages, reactions, and relay behaviors.
Security & Trust Considerations
Nostr relays are simple servers that forward messages, but their decentralized nature introduces unique security and trust models distinct from traditional client-server architectures.
Relay Censorship & Data Availability
A Nostr relay can arbitrarily censor users by refusing to store or broadcast their events. This creates a data availability risk where a user's messages may not be accessible to their intended audience. Users mitigate this by publishing to multiple, geographically diverse relays, ensuring no single operator controls their presence on the network.
- Example: A relay operator in a specific jurisdiction might block content based on local laws.
- Strategy: Clients like Damus or Amethyst allow users to configure multiple relay endpoints for redundancy.
Ephemeral vs. Paid/Private Relays
Relays operate on different business and persistence models that directly impact security and privacy.
- Ephemeral/Public Relays: Often free but may prune old data or have no uptime guarantees. Trust is low; data can disappear.
- Paid Relays: (e.g., nostr.fan, nostr.wine) Use NIP-05-like authentication or Bitcoin payments. They often offer better uptime, support, and explicit data retention policies, creating a clearer trust contract.
- Private Relays: Self-hosted or closed relays limit exposure to public spam and censorship but require personal maintenance.
Spam & Denial-of-Service (DoS) Vulnerabilities
As open pub/sub servers, relays are vulnerable to spam attacks and resource exhaustion. Malicious actors can publish a high volume of events to degrade performance for all users.
- Mitigation (Relay Side): Operators use rate limiting, proof-of-work requirements (NIP-13), and whitelists/blacklists for pubkeys.
- Mitigation (Client Side): Clients implement filters and user mute lists to hide unwanted content. The lack of a global fee market means spam resistance is managed locally by each relay operator.
Data Integrity & Signature Verification
Trust in data integrity is cryptographic, not relational. A relay cannot tamper with the content of a signed Nostr event without breaking its Schnorr signature. However, a malicious relay can:
- Withhold events (censorship).
- Serve stale or incorrect event order.
- Inject fake events from other valid users (if it possesses their private key, which is a key compromise, not a relay flaw).
Client verification is mandatory: clients must always validate signatures and created_at timestamps, treating the relay as an untrusted data carrier.
Network Surveillance & Metadata Leaks
Relay operators can perform network surveillance, collecting rich metadata even on encrypted content (NIP-04, NIP-44). This metadata includes:
- Social Graph: All follower/following (contact list) relationships.
- Posting Times & Habits: Behavioral fingerprints from event timestamps.
- IP Addresses: Unless using Tor or VPN, a user's IP is logged on connection.
Using anonymous networks (Tor) and choosing relays in privacy-friendly jurisdictions are common countermeasures. Decentralization limits any single operator's view.
Client-Side Security is Paramount
In Nostr's decentralized model, ultimate security responsibility falls on the client software. Users must:
- Safeguard their private key (nsec). Loss means permanent, unrecoverable identity loss.
- Verify the authenticity of followers and messages through out-of-band key comparison (e.g., using NIP-05 verified usernames).
- Audit relay lists and connections, as malicious relays could feed false data.
This user-centric security model removes central points of failure but increases individual operational burden compared to managed web2 services.
Nostr Relay vs. Traditional Social Server
A technical comparison of the core architectural and operational differences between a decentralized Nostr Relay and a centralized social media server.
| Feature / Metric | Nostr Relay | Traditional Social Server |
|---|---|---|
Architectural Model | Stateless, Permissionless Relay | Centralized, Stateful Application Server |
Data Ownership & Portability | User-held private keys, data is portable | Platform-owned, data is siloed |
Censorship Resistance | ||
Server Operator Responsibility | Relays messages, optional filtering | Hosts content, enforces global policy |
Client Authentication | Cryptographic signatures (public/private keys) | Username/password, OAuth, platform account |
Global State & Social Graph | Distributed across clients & relays | Centrally stored and managed |
Server Redundancy & Uptime | User can connect to multiple relays | Single point of failure (platform) |
Monetization Model | Relay fees, donations, optional | Advertising, data monetization, subscriptions |
Ecosystem & Implementation
A Nostr relay is a server that receives, stores, and broadcasts events for the decentralized Nostr protocol. This section details its operational components and ecosystem roles.
Core Function: Event Handling
A relay's primary function is to process NOSTR events (JSON objects with a kind, pubkey, and content). It performs signature verification to ensure authenticity, stores valid events, and broadcasts them to connected clients. Relays can implement custom filtering logic, such as rejecting certain event types or content, making them more than simple pass-through servers.
Architecture & Communication
Relays communicate with clients (like wallets or social apps) via a simple WebSocket-based protocol. Clients send subscription requests with filters (e.g., {"authors": ["pubkey..."]}) and the relay streams matching events. This publish-subscribe (pub/sub) model is stateless and efficient, allowing for real-time updates across the network.
Types of Relays
Relays vary in purpose and policy:
- Public Relays: Open to all, forming the backbone of the network (e.g.,
relay.damus.io). - Private Relays: Restricted to specific users, often for enhanced privacy or control.
- Paid Relays: Require payment (often via Bitcoin Lightning) for posting or access, mitigating spam.
- Write-Only/Archive Relays: Specialized for data persistence or specific event kinds.
Economic Model & Incentives
Running a relay has costs (bandwidth, storage). Common models include:
- Volunteer/Donation: Funded by community support.
- Paid Posting: Users pay a small Lightning Network fee (sats) to publish, creating a spam-resistant economic layer.
- Tiered Access: Premium features for paying subscribers. This creates a sustainable ecosystem without centralized advertising.
Client-Relay Relationship
A Nostr client (app) typically connects to multiple relays for redundancy and censorship resistance. It aggregates data using the NIP-65 relay list metadata. The decentralized trust model means users must choose relays wisely, balancing speed, privacy, and reliability. No single relay is authoritative.
Frequently Asked Questions (FAQ)
Essential questions and answers about the decentralized communication infrastructure of the Nostr protocol.
A Nostr relay is a simple, stateless server that receives, stores, and broadcasts messages (events) for users of the Nostr protocol. It functions as a public bulletin board where clients (like apps) can publish signed events and subscribe to receive events from other users they follow. Unlike federated servers, relays are independent; a user can publish to and read from multiple relays simultaneously to ensure censorship resistance and data redundancy. The relay's primary job is to validate the cryptographic signature on incoming events and then make them available to any client that requests them via a persistent WebSocket connection.
Get In Touch
today.
Our experts will offer a free quote and a 30min call to discuss your project.