Vercel is the creators of Next.js and offers the best Next.js hosting experience. This setup uses a hybrid approach: Vercel for the web app and a small worker service for background jobs.
Why Vercel?
- Best-in-class Next.js support
- Automatic deployments from GitHub
- Edge network for fast global access
- Generous free tier
- Zero configuration needed
Important Limitation
Vercel serverless functions have a maximum execution time (10s on free, 60s on Pro). Maillayer's background workers (email processing, campaigns) need persistent execution.
Solution: Run the web app on Vercel and workers on a separate service (Railway/Render) or use Vercel's new Fluid Compute for longer tasks.
Prerequisites
- A GitHub account
- Vercel account (sign up at vercel.com)
- MongoDB Atlas account
- Upstash account for Redis
Step 1: Set Up MongoDB Atlas
- Go to mongodb.com/atlas
- Create a free M0 cluster
- Create a database user
- In Network Access, add
0.0.0.0/0to allow all IPs - Copy the connection string
Step 2: Set Up Upstash Redis
- Go to upstash.com and create an account
- Click Create Database
- Select a region close to your users
- Choose Free tier for testing
- Copy the REST URL and REST Token (or standard Redis URL)
Step 3: Deploy to Vercel
- Go to vercel.com/new
- Import your Maillayer GitHub repository
- Vercel auto-detects Next.js settings
Step 4: Configure Environment Variables
In Vercel's project settings, add these environment variables:
NODE_ENV=production
BASE_URL=https://your-project.vercel.app
NEXTAUTH_SECRET=your-secret-key-minimum-32-characters
TRACKING_SECRET=your-tracking-secret
MONGODB_URI=mongodb+srv://user:password@cluster.mongodb.net/maillayer
REDIS_URL=redis://default:token@your-redis.upstash.io:6379
Step 5: Modify Build for Vercel
Create or update vercel.json in your project root:
{
"buildCommand": "npm run build",
"outputDirectory": ".next",
"framework": "nextjs"
}
Step 6: Deploy Workers Separately
Since Vercel can't run persistent workers, deploy them to Railway or Render:
Option A: Railway Worker Service
- Create a new Railway project
- Add your repo but override the start command:
node workers/email-processor.js & node workers/campaign-manager.js & node workers/cron-checker.js & wait - Add the same
MONGODB_URIandREDIS_URLenvironment variables
Option B: Use a Simple VPS
Run a small DigitalOcean droplet just for workers (new accounts get $200 free credit):
# On the VPS
git clone your-repo
cd maillayer
npm install
pm2 start ecosystem.config.js --only email-worker,cron-checker,campaign-manager
Step 7: Deploy
- Push to your main branch
- Vercel auto-deploys
- Access your app at
https://your-project.vercel.app
Adding a Custom Domain
- Go to Project Settings → Domains
- Add your domain
- Configure DNS as instructed
- Update
BASE_URLin environment variables
Estimated Costs
| Resource | Free Tier | Production |
|---|---|---|
| Vercel | 100GB bandwidth | $20/month (Pro) |
| MongoDB Atlas | Free M0 | $9/month (M2) |
| Upstash Redis | 10k commands/day | $10/month |
| Worker Service | - | $5-7/month |
Total: Free tier possible for testing, ~$25-45/month for production.
Troubleshooting
API routes timing out
- Vercel free tier has 10s limit. Upgrade to Pro for 60s, or optimize long operations.
Workers not processing emails
- Ensure worker service is running. Check Railway/Render logs.
Database connection errors
- Verify MongoDB Atlas allows connections from all IPs.
Redis connection issues
- Upstash provides both REST and standard Redis URLs. Use the standard Redis URL for Bull queue compatibility.
When to Choose Vercel
✅ Choose Vercel if:
- You want the best Next.js experience
- Your email volume is moderate
- You're comfortable splitting workers to another service
❌ Consider alternatives if:
- You want everything in one place
- You need persistent background processes
- You're sending high-volume campaigns
