When to Use Railway vs Vercel
Use Vercel for Next.js apps that are purely serverless (frontend + API routes).
- Use Railway when your app needs:
- A persistent server (WebSockets, background jobs, cron)
- A Node.js/Python/Go backend process
- A database alongside your app
- Your Vercel function keeps timing out
Time: ~15 minutes Prerequisites: Code on GitHub (guide)
Step 1: Create Railway Account and Deploy
Go to railway.com → Sign up with GitHub → New Project → Deploy from GitHub repo → Select your repository → Deploy Now.
Railway's free tier includes $5 credit monthly — enough for a small app with low traffic.
Checkpoint: Railway shows your app building. When done, click "Generate Domain" in Settings to get your URL.
If the build fails, add NODE_ENV=production to Railway variables. See Railway deploy fix.
Step 2: Add Environment Variables
Railway Dashboard → Your Service → Variables → Add all variables from your .env.local.
Railway restarts your app automatically after adding variables.
Step 3: Configure Start Command
If Railway doesn't auto-detect your framework, go to Settings → Deploy → Start Command:
# Next.js npm run start # Node.js Express node server.js # Python FastAPI uvicorn main:app --host 0.0.0.0 --port $PORT
Always use $PORT — Railway assigns the port automatically.
Step 4: Connect Your Domain
Railway Dashboard → Settings → Networking → Custom Domain → Enter your domain.
Add the CNAME record Railway shows you at your domain registrar.
Checkpoint: your-domain.com loads from Railway with green SSL padlock.
Step 5: Set Up Stripe Webhooks
If your app uses Stripe, add the webhook URL:
Stripe Dashboard → Developers → Webhooks → Add endpoint:
https://your-app.up.railway.app/api/webhooks/stripe
Select events: checkout.session.completed, customer.subscription.deleted, invoice.payment_failed.