Production Deployment
This guide covers best practices, architecture patterns, and operational considerations for deploying Moq in production.Architecture Overview
A production Moq deployment typically consists of:Component Roles
- Origin Relays: Receive content from publishers, authenticate, validate
- Regional Relays: Aggregate traffic, provide redundancy, span continents
- Edge Relays: Serve viewers, cache content, distributed globally
- Root Relay: Coordinates cluster, tracks broadcasts (can be any relay)
Deployment Checklist
TLS Certificates
Use valid TLS certificates from Let’s Encrypt or a commercial CA. Self-signed certificates are not suitable for production.
Multi-Region Deployment
Three-Tier Architecture
For global deployments:Configuration Example
Origin Relay (us-east-1):origin.toml
regional.toml
edge.toml
High Availability
Load Balancing
DNS Round-Robin
Simplest approach:- Simple to implement
- No additional infrastructure
- No health checking
- Clients may cache DNS
- Not latency-aware
GeoDNS
Route users to nearest relay:Anycast
Multiple relays share the same IP address:- Automatic failover
- Lowest latency (network-layer routing)
- No DNS caching issues
- Requires BGP setup
- More complex infrastructure
- Typically needs hosting with anycast support
Health Checking
Monitor relay health:Redundant Origins
Deploy origins in active-active or active-passive: Active-Passive:Security
Network Security
Firewall Rules
- Allow only UDP 443 and TCP 443
- Restrict management ports to internal IPs
- Use security groups/firewall rules
DDoS Protection
- Use DDoS protection service (Cloudflare, AWS Shield)
- Rate limit connections per IP
- Monitor for anomalies
Private Networks
- Use private networking for relay-to-relay communication
- VPN or VPC peering between regions
- Keep cluster tokens on private network
Intrusion Detection
- Monitor logs for suspicious activity
- Alert on authentication failures
- Track connection patterns
Application Security
Authentication
Always enable authentication in production:Token Security
- Short-lived tokens: 1-24 hours maximum
- Refresh tokens: Issue new tokens before expiration
- Revocation: Rotate keys to revoke all tokens
- Minimal permissions: Only grant needed publish/subscribe rights
Secrets Management
Never commit keys to version control:TLS Best Practices
- Use Let’s Encrypt: Free, automated, trusted
- Auto-renewal: Set up certbot auto-renewal
- Strong ciphers: Let QUIC handle cipher selection
- Certificate monitoring: Alert before expiration
Monitoring & Observability
Metrics to Track
- Infrastructure
- Application
- Quality
- CPU usage
- Memory usage
- Network bandwidth (in/out)
- Disk I/O
- UDP packet loss
- Connection count
Logging
Alerting
Set up alerts for:- Relay down (health check fails)
- High CPU usage (over 80%)
- High memory usage (over 90%)
- Certificate expiring (less than 7 days)
- Authentication failure spike
- Abnormal traffic patterns
Performance Optimization
Operating System
Hardware Recommendations
Origin Relays
- CPU: 8-16 cores
- RAM: 16-32 GB
- Network: 10 Gbps
- Storage: Fast SSD for caching
Regional Relays
- CPU: 16-32 cores
- RAM: 32-64 GB
- Network: 10-40 Gbps
- Storage: NVMe SSD
Edge Relays
- CPU: 4-8 cores
- RAM: 8-16 GB
- Network: 1-10 Gbps
- Storage: SSD for caching
Cloud Provider Recommendations
- AWS
- Google Cloud
- Azure
Origin: c7g.2xlarge (8 vCPU, 16 GB RAM)Regional: c7g.4xlarge (16 vCPU, 32 GB RAM)Edge: c7g.xlarge (4 vCPU, 8 GB RAM)Use Elastic IP or ALB with UDP support.
Scaling
Horizontal Scaling
Add more relays as traffic grows:Auto-scaling
With Kubernetes or cloud auto-scaling:Backup & Disaster Recovery
Configuration Backup
Recovery Plan
Cost Optimization
Bandwidth Costs
Moq’s biggest cost is typically bandwidth:- Clustering reduces costs: Route traffic optimally
- Caching: Edge relays cache content
- Deduplication: One source, many viewers
- Quality adaptation: Lower quality = less bandwidth
Cloud Cost Tips
- Use spot/preemptible instances for non-critical edge relays
- Reserved instances for origin/regional relays
- Multi-cloud to leverage free egress tiers
- Monitor bandwidth with usage alerts
Troubleshooting
Relay frequently restarting
Relay frequently restarting
- Check logs:
journalctl -u moq-relay -n 100 - Look for OOM kills:
dmesg | grep -i oom - Check disk space:
df -h - Verify config file is valid
High latency
High latency
- Check geographic distance to relay
- Verify network path:
mtr relay.example.com - Check relay CPU usage
- Verify QUIC is not being blocked
- Test with different DNS resolver
Cluster relays disconnecting
Cluster relays disconnecting
- Check network connectivity between relays
- Verify cluster token is valid and not expired
- Check for firewall rules blocking relay-to-relay traffic
- Ensure root relay is accessible from all leaves
Certificate errors
Certificate errors
- Verify certificate is not expired:
openssl x509 -in cert.pem -noout -dates - Check certificate matches hostname
- Ensure full chain is provided
- Check Let’s Encrypt rate limits
Next Steps
Relay Setup
Detailed relay configuration
Authentication
Setup JWT authentication
Publishing
Connect publishers to production relay
Monitoring
Advanced monitoring and debugging