Nostr Relays
Relays are the servers that store and forward Nostr events. For financial applications, relay selection and reliability are critical considerations.
What Are Relays?
Relays are:
- Message brokers that accept and serve events
- Decentralized - anyone can run one
- Independent - each has its own policies
- The backbone of Nostr's infrastructure
Relay Types
Free Relays
Open to everyone:
- No cost to write/read
- Often run by enthusiasts
- May have limited retention
- Higher spam potential
Paid Relays
Require payment:
- One-time or subscription fee
- Better spam filtering
- Higher reliability
- Longer data retention
Private Relays
Restricted access:
- Whitelist-based
- Often for communities
- Maximum control
- Custom policies
Relay Selection for Finance
Critical Factors
| Factor | Importance | Why |
|---|---|---|
| Uptime | Critical | Payments need delivery |
| Retention | High | Historical data access |
| Speed | High | Real-time transactions |
| Privacy | Medium | Financial data sensitivity |
Recommended Strategy
Finance-Specific Considerations
NWC Relays
For Nostr Wallet Connect:
- Reliability essential for payment flow
- Fast message delivery
- Good uptime record
Commonly used:
wss://relay.getalby.com/v1wss://nostr.mutinywallet.com
Zap Receipts
For zap receipt delivery:
- Include multiple relays in requests
- Use relays recipient is connected to
- Check relay list in profiles
On-Chain Coordination
For on-chain payments:
- Publish PSBTs to trusted relays
- Use encrypted messages for sensitive data
- Ensure delivery confirmation
Running Your Own Relay
Benefits
- Full control over your data
- Guaranteed access to your events
- Privacy from third parties
- Custom policies
Options
| Software | Language | Features |
|---|---|---|
| strfry | C++ | High performance |
| nostream | TypeScript | Feature-rich |
| nostr-rs-relay | Rust | Configurable |
| relay | Go | Simple setup |
Basic Setup (strfry)
# Clone and build
git clone https://github.com/hoytech/strfry
cd strfry
make setup-golpe
make -j4
# Configure
cp strfry.conf myrelay.conf
# Edit configuration
# Run
./strfry relay
Relay Policies
Event Filtering
Relays can restrict:
- Event kinds accepted
- Pubkeys allowed
- Content types
- Event size
Rate Limiting
Common limits:
- Events per minute
- Connections per IP
- Bandwidth per user
Data Retention
Policies vary:
- Forever (rare)
- Time-based (e.g., 90 days)
- Size-based (newest kept)
- Kind-based (some permanent)
Monitoring Relays
Health Checks
async function checkRelay(url) {
try {
const start = Date.now();
const ws = new WebSocket(url);
await new Promise((resolve, reject) => {
ws.onopen = resolve;
ws.onerror = reject;
setTimeout(reject, 5000);
});
const latency = Date.now() - start;
ws.close();
return { status: 'up', latency };
} catch {
return { status: 'down', latency: null };
}
}
Tools
- nostr.watch - Relay monitoring
- relay.tools - Relay info
- Custom monitoring dashboards
Best Practices
For Users
- Use multiple relays - Redundancy is key
- Include paid relays - Better reliability
- Test regularly - Ensure connectivity
- Backup data - Don't rely solely on relays
For Financial Apps
- Retry logic - Handle failures gracefully
- Multiple paths - Write to several relays
- Confirmation - Verify event publication
- Timeouts - Don't wait forever
Example: Robust Publishing
async function publishWithRetry(event, relays, maxRetries = 3) {
const results = [];
for (const relay of relays) {
let attempt = 0;
while (attempt < maxRetries) {
try {
await publishToRelay(event, relay);
results.push({ relay, success: true });
break;
} catch (error) {
attempt++;
if (attempt === maxRetries) {
results.push({ relay, success: false, error });
}
await sleep(1000 * attempt); // Exponential backoff
}
}
}
const successCount = results.filter(r => r.success).length;
if (successCount === 0) {
throw new Error('Failed to publish to any relay');
}
return results;
}
Resources
Financial Reliability
For financial applications, relay reliability directly impacts user experience. Invest in good relay connections - a few dollars per month for paid relays is worthwhile insurance.