Production Deployment Guide
This guide covers deploying vuer-rtc applications to production environments, including client deployment, server deployment, database setup, and scaling considerations.
Overview
A production vuer-rtc deployment consists of:
- Client Application: Static site (React/Next.js) deployed to CDN/edge network
- RTC Server: Node.js server with WebSocket support
- MongoDB: Replica set for Change Streams (minimum 1 node)
- Redis: For pub/sub and session management
- SSL/TLS: Required for secure WebSocket connections
1. Client Deployment
The client is a static site that can be deployed to any CDN or edge network.
Netlify Deployment
Setup:
-
Install Netlify CLI:
-
Configure
netlify.toml: -
Set environment variables in Netlify dashboard or CLI:
-
Deploy:
2. Server Deployment
The RTC server requires WebSocket support and persistent connections.
Railway Deployment
Railway offers excellent WebSocket support and automatic scaling.
Setup:
-
Install Railway CLI:
-
Initialize project:
-
Create
railway.json: -
Set environment variables:
-
Deploy:
Environment Variables:
| Variable | Example | Description |
|---|---|---|
MONGODB_URI | mongodb+srv://user:pass@cluster.mongodb.net/vuer-rtc?replicaSet=atlas-... | MongoDB connection string (must be replica set) |
REDIS_URL | redis://:password@redis.example.com:6379 | Redis connection string |
NODE_ENV | production | Node environment |
CORS_ORIGIN | https://app.example.com | Allowed CORS origins (comma-separated) |
PORT | 3000 | Server port (Railway auto-assigns) |
Render Deployment
Setup:
-
Create
render.yaml: -
Connect to GitHub and deploy via Render dashboard
-
Add environment variables in Render dashboard
AWS Deployment (ECS Fargate)
Dockerfile:
ECS Task Definition:
Fly.io Deployment
Setup:
-
Install Fly CLI:
-
Create
fly.toml: -
Set secrets:
-
Deploy:
3. MongoDB Atlas Setup
MongoDB Atlas provides managed MongoDB with built-in replica sets.
Setup Steps:
-
Create Cluster:
- Go to cloud.mongodb.com
- Create a new cluster (M0 free tier works for development)
- Choose region closest to your server
-
Configure Network Access:
-
Create Database User:
-
Get Connection String:
Example connection string:
Important: Atlas clusters are automatically configured as replica sets!
-
Create Indexes (Optional but recommended):
Environment Variable:
4. Redis Cloud Setup
Redis Cloud provides managed Redis with persistence and high availability.
Setup Steps:
-
Create Database:
- Go to redis.com/try-free
- Create a free 30MB database
- Choose region closest to your server
-
Get Connection String:
Example:
-
Configure Persistence (Optional):
Environment Variable:
Alternative: Upstash (Serverless Redis)
5. Environment Variables Checklist
Client (.env.production)
Server (.env.production)
6. CORS Configuration for WebSockets
WebSocket connections require proper CORS configuration.
Server Configuration (Fastify):
Client Configuration:
7. SSL/TLS for WebSocket Connections
Production WebSocket connections must use WSS (WebSocket Secure).
Automatic SSL (Recommended)
Most platforms handle SSL automatically:
| Platform | SSL Setup |
|---|---|
| Railway | Automatic SSL via Railway domains or custom domains |
| Render | Automatic SSL via Let's Encrypt |
| Fly.io | Automatic SSL via Let's Encrypt |
| Netlify | Automatic SSL for all deployments |
Manual SSL (Nginx + Let's Encrypt)
If self-hosting, use Nginx as a reverse proxy:
Install Certbot:
Nginx Configuration (/etc/nginx/sites-available/vuer-rtc):
Enable and get certificate:
Auto-renewal:
8. Scaling Considerations
Horizontal Scaling
Use Redis Pub/Sub to synchronize state across multiple server instances.
Architecture:
Implementation:
Load Balancing
Railway/Render: Automatic load balancing with multiple instances
AWS ALB Configuration:
Important: Enable sticky sessions (session affinity) for WebSocket connections!
Database Scaling
MongoDB Atlas:
Sharding (Advanced):
9. Health Checks and Monitoring
Health Check Endpoint
Monitoring with Sentry
Install:
Setup:
Logging
10. Backup and Disaster Recovery
MongoDB Backup
Automated Backups (Atlas):
Atlas provides automatic daily backups with point-in-time recovery:
Manual Backup:
Backup Strategy:
Cron job:
Redis Backup
Redis Cloud: Automatic daily backups
Manual Backup:
Disaster Recovery Plan
-
Regular Backups:
- MongoDB: Daily automated backups via Atlas
- Redis: Daily snapshots
- Code: GitHub repository
-
Recovery Procedures:
-
Failover Strategy:
- Use MongoDB Atlas automatic failover
- Deploy to multiple regions (Railway/Render supports this)
- Implement circuit breakers in client code
-
Testing:
Monitoring Alerts
Setup alerts for:
- Server downtime (health check failures)
- High memory/CPU usage (>80%)
- Database connection failures
- WebSocket connection spikes
- High error rates (>1% of requests)
Example (Railway):
Example (Sentry):
Quick Start Checklist
-
Client deployed (Netlify)
- Environment variables set (
VITE_RTC_SERVER_URL,VITE_RTC_SERVER_WS) - SSL/HTTPS enabled
- Environment variables set (
-
Server deployed (Railway/Render/AWS/Fly.io)
- WebSocket support enabled
- Environment variables set
- Health check endpoint working (
/health)
-
MongoDB Atlas configured
- Cluster created (replica set enabled)
- Database user created
- Network access configured
- Connection string added to server
-
Redis Cloud configured
- Database created
- Connection string added to server
-
CORS configured
- Client origin whitelisted
- WebSocket origin verification enabled
-
SSL/TLS enabled
- Client uses HTTPS
- Server uses WSS for WebSockets
-
Monitoring setup
- Health checks enabled
- Logging configured
- Error tracking (Sentry) enabled
-
Backups configured
- MongoDB daily backups enabled
- Redis snapshots enabled
- Disaster recovery plan documented
Troubleshooting
WebSocket Connection Fails
Symptoms: Client cannot connect, "WebSocket connection failed" error
Solutions:
-
Check CORS:
-
Verify SSL:
-
Check server logs:
MongoDB Replica Set Error
Symptoms: MongoServerError: The command requires replica set
Solution: Ensure connection string includes replicaSet parameter:
High Latency
Symptoms: Slow updates, delayed synchronization
Solutions:
-
Check region proximity:
- Deploy server close to MongoDB cluster
- Use same cloud provider for server and database
-
Enable connection pooling:
-
Optimize queries:
Memory Leaks
Symptoms: Increasing memory usage over time
Solutions:
-
Monitor with metrics:
-
Clean up stale connections:
-
Limit journal size: