Overview
This guide covers deploying Dub to various hosting platforms. Dub is a Next.js application that can be deployed to any platform that supports Node.js.Deployment Requirements
System Requirements
- Node.js 23.11.0 or higher
- pnpm 9.15.9 or higher
- 2GB+ RAM (4GB+ recommended)
- 10GB+ disk space
- MySQL 8.0+ database
External Services
Ensure you have the following services configured:- MySQL Database - See Database Setup
- Tinybird - For analytics
- Upstash Redis - For caching
- Upstash QStash - For background jobs
- Email Service - Resend or SMTP
- Domain Provider - For custom domains
Vercel (Recommended)
Vercel is the recommended platform for deploying Next.js applications, including Dub.Connect Repository
- Push your Dub fork to GitHub
- Go to vercel.com/new
- Import your repository
- Select the
apps/webdirectory as the root
Configure Build Settings
Set the following build configuration:
- Framework Preset: Next.js
- Root Directory:
apps/web - Build Command:
cd ../.. && pnpm install && pnpm build --filter=web - Install Command:
pnpm install - Output Directory:
.next
Set Environment Variables
Add all required environment variables in Vercel project settings.See Environment Variables for the complete list.
You don’t need to set
NEXTAUTH_URL on Vercel - it’s automatically detected.Configure Domains
- Add your custom domain in Vercel project settings
- Update DNS records as instructed
- Wait for SSL certificate provisioning
Enable Cron Jobs
Vercel automatically detects cron jobs from
vercel.json.Verify cron jobs are enabled in Project Settings → Cron Jobs.Cron jobs require a Vercel Pro plan or higher.
Vercel Configuration
Dub includes avercel.json configuration file:
vercel.json
Railway
Railway provides simple deployment for full-stack applications.Create New Project
- Go to railway.app
- Click “New Project”
- Select “Deploy from GitHub repo”
- Choose your Dub repository
Set Environment Variables
Add all environment variables in Railway service settings.Railway provides a PostgreSQL database, but Dub requires MySQL. Add a MySQL service separately.
Add MySQL Service
- Click “New” → “Database” → “Add MySQL”
- Copy the connection string
- Add as
DATABASE_URLenvironment variable
Railway Cron Jobs
Railway doesn’t have built-in cron support. Use external services:- Upstash QStash Schedules - Set up scheduled HTTP requests
- Cron-job.org - Free cron job service
- EasyCron - Paid cron service with monitoring
CRON_SECRET header.
Docker Deployment
Deploy Dub using Docker for maximum control.Create Dockerfile
CreateDockerfile in the repository root:
Dockerfile
Build and Run
Docker Compose
Createdocker-compose.prod.yml:
docker-compose.prod.yml
AWS EC2
Deploy to Amazon EC2 for full infrastructure control.Launch EC2 Instance
- Choose Ubuntu Server 22.04 LTS
- Instance type: t3.medium or larger
- Configure security group:
- Allow SSH (port 22)
- Allow HTTP (port 80)
- Allow HTTPS (port 443)
EC2 Cron Jobs
Set up cron jobs using crontab:DigitalOcean App Platform
Create New App
- Go to DigitalOcean App Platform
- Click “Create App”
- Connect your GitHub repository
Configure Build
- Source Directory:
apps/web - Build Command:
cd ../.. && pnpm install && pnpm build --filter=web - Run Command:
cd apps/web && pnpm start
Render
Create Web Service
- Go to render.com
- Click “New” → “Web Service”
- Connect your repository
Configure Service
- Root Directory:
apps/web - Build Command:
cd ../.. && pnpm install && pnpm build --filter=web - Start Command:
cd apps/web && pnpm start
Cloudflare Pages
Environment-Specific Configuration
Production Environment Variables
For production, ensure these are properly configured:Cron Jobs Configuration
Dub requires several cron jobs for proper operation:Required Cron Jobs
| Endpoint | Schedule | Description |
|---|---|---|
/api/cron/domains/verify | 0 * * * * | Verify domain DNS records |
/api/cron/email-domains/verify | 0 * * * * | Verify email domains |
/api/cron/streams/update-workspace-clicks | * * * * * | Update workspace click counts |
/api/cron/streams/update-partner-stats | */2 * * * * | Update partner statistics |
/api/cron/usage | 0 12 * * * | Generate usage reports |
/api/cron/aggregate-clicks | 0 0 * * * | Aggregate daily click data |
Securing Cron Endpoints
SetCRON_SECRET environment variable and include it in cron requests:
Health Checks
Set up health checks for monitoring:Monitoring & Logging
Application Monitoring
Configure Axiom for logging:Uptime Monitoring
Use services like:- UptimeRobot - Free uptime monitoring
- Pingdom - Advanced monitoring and alerts
- Better Uptime - Status pages and incident management
Scaling Considerations
Horizontal Scaling
For high traffic:- Deploy multiple instances
- Use a load balancer (AWS ALB, Cloudflare, etc.)
- Ensure session affinity if using in-memory sessions
- Use Redis for session storage
Vertical Scaling
Increase server resources:- CPU: 2+ cores for production
- RAM: 4GB minimum, 8GB+ recommended
- Storage: SSD with 20GB+ free space
Database Scaling
- Use read replicas for analytics queries
- Enable query caching
- Optimize indexes
- Consider database connection pooling
Troubleshooting
Build Failures
Runtime Errors
Check logs:Database Connection Issues
Verify connectivity:Production Checklist
- All environment variables are set
- Database is configured and accessible
- SSL/TLS certificates are installed
- Cron jobs are scheduled and running
- Monitoring and logging are configured
- Backup procedures are in place
- Health checks are configured
- Domain DNS is properly configured
- Email delivery is tested and working
- Rate limiting is enabled (via Edge Config)
- Security headers are configured
- Application performance is optimized