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

  1. Go to mongodb.com/atlas
  2. Create a free M0 cluster
  3. Create a database user
  4. In Network Access, add 0.0.0.0/0 to allow all IPs
  5. Copy the connection string

Step 2: Set Up Upstash Redis

  1. Go to upstash.com and create an account
  2. Click Create Database
  3. Select a region close to your users
  4. Choose Free tier for testing
  5. Copy the REST URL and REST Token (or standard Redis URL)

Step 3: Deploy to Vercel

  1. Go to vercel.com/new
  2. Import your Maillayer GitHub repository
  3. 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

  1. Create a new Railway project
  2. Add your repo but override the start command:
    node workers/email-processor.js & node workers/campaign-manager.js & node workers/cron-checker.js & wait
    
  3. Add the same MONGODB_URI and REDIS_URL environment 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

  1. Push to your main branch
  2. Vercel auto-deploys
  3. Access your app at https://your-project.vercel.app

Adding a Custom Domain

  1. Go to Project SettingsDomains
  2. Add your domain
  3. Configure DNS as instructed
  4. Update BASE_URL in environment variables

Estimated Costs

ResourceFree TierProduction
Vercel100GB bandwidth$20/month (Pro)
MongoDB AtlasFree M0$9/month (M2)
Upstash Redis10k 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