Skip to main content
This guide covers deploying GUN relay peers to production environments. Relay peers help browser clients discover each other and provide persistent storage for your decentralized application.

Quick Deploy Options

Heroku

One-click deploy to Heroku: Deploy Source: ~/workspace/source/README.md:271 Or manually:
Source: ~/workspace/source/README.md:277-282 Note: Heroku’s ephemeral filesystem deletes data every ~15 minutes. For production, add persistent storage. Source: ~/workspace/source/README.md:273

Docker

Pull from Docker Hub:
Source: ~/workspace/source/README.md:301 Or build locally:
Source: ~/workspace/source/README.md:306-311

Dockerfile Reference

GUN’s Dockerfile uses a multi-stage build:
Source: ~/workspace/source/Dockerfile Exposed Ports:
  • 8765: Default GUN relay port
  • 8080: Alternative HTTP port

Linux Server

Deploy on a clean Linux server:
Source: ~/workspace/source/README.md:254 Note: Review the install script before running. It installs Node.js, clones GUN, and starts the relay peer. Detach from the session:
Source: ~/workspace/source/README.md:260-261

Environment Variables

Core Configuration

Source: ~/workspace/source/examples/http.js:7-11, ~/workspace/source/lib/axe.js:12, ~/workspace/source/lib/multicast.js:7

Build Configuration

Source: ~/workspace/source/README.md:245 Why needed: When deploying web apps with GUN on cloud providers, build systems may treat GUN’s warnings as errors.

HTTPS Configuration

Automatic HTTPS Detection

GUN automatically enables HTTPS if certificate files exist:
Source: ~/workspace/source/examples/http.js:14-21

Manual HTTPS Configuration

Source: ~/workspace/source/examples/http.js:22-27

Let’s Encrypt

Use Certbot for free SSL certificates:

Nginx Reverse Proxy

For complex setups, use Nginx:
Source: Referenced in ~/workspace/source/README.md:262

Storage Configuration

File System Storage (Default)

Source: File storage is included in ~/workspace/source/lib/server.js:15

RAD Storage (Optimized)

Radix storage for better performance:

Amazon S3 Storage

For Heroku and other ephemeral filesystems:
Source: S3 adapter at ~/workspace/source/lib/rs3.js, mentioned in ~/workspace/source/README.md:273

Custom Storage Adapter

Implement your own storage:

Process Management

Systemd Service

Create /etc/systemd/system/gun.service:

Clustering

GUN includes automatic clustering:
Source: ~/workspace/source/examples/http.js:2-5

Network Topology

Single Relay Peer

Simplest setup for small applications:

Multiple Relay Peers

Redundancy and load balancing:

Geographic Distribution

Distribute relays globally for lower latency:
Clients connect to nearest relay.

Hybrid Architecture

Public relays for browser clients, private relays for backend services.

Monitoring and Logging

Enable Statistics

Source: Referenced in ~/workspace/source/src/mesh.js:328

Structured Logging

Health Check Endpoint

Error Tracking

Security Best Practices

1. Use HTTPS/WSS

Always use encrypted connections in production:

2. Rate Limiting

3. Message Size Limits

Source: ~/workspace/source/src/mesh.js:15

4. Authentication

Use GUN’s SEA for user authentication:

5. CORS Configuration

Performance Tuning

Optimize for Relay Role

Source: ~/workspace/source/lib/server.js:8-9

Connection Limits

Memory Management

Backup and Recovery

Automated Backups

Data Export

Data Import

Troubleshooting

Connection Issues

Memory Leaks

Storage Issues

Deployment Checklist

  • HTTPS/WSS enabled
  • Environment variables configured
  • Storage backend configured
  • Process manager (PM2/systemd) configured
  • Monitoring and logging enabled
  • Health checks implemented
  • Rate limiting enabled
  • CORS configured
  • Backup strategy implemented
  • Multiple relay peers deployed
  • Geographic distribution (if needed)
  • Auto-restart on crash configured
  • Memory limits set
  • Error tracking enabled
  • Load testing completed

Next Steps