Deployment Architecture
Option 1: Vercel + Railway (Recommended)
Deploy the frontend to Vercel and the backend to Railway for optimal performance.Deploy API to Railway
Create Railway project
- Sign up at railway.app
- Click “New Project” → “Deploy from GitHub repo”
- Select your Drift repository
Configure build settings
In Railway project settings:Root Directory: Start Command:Watch Paths:
apps/apiBuild Command:apps/api/**Deploy Web to Vercel
Connect repository
- Sign up at vercel.com
- Click “Add New” → “Project”
- Import your Drift GitHub repository
Configure build settings
Framework Preset: Next.jsRoot Directory: Output Directory:
apps/webBuild Command:apps/web/.nextInstall Command:Set environment variables
In Vercel project settings → Environment Variables:
Only variables prefixed with
NEXT_PUBLIC_ are accessible in the browser.Option 2: Docker Deployment
Deploy both services using Docker containers.API Dockerfile
Createapps/api/Dockerfile:
Web Dockerfile
Createapps/web/Dockerfile:
Docker Compose
Createdocker-compose.yml at the repository root:
Option 3: All-in-One Platforms
Render
Create Web Service
- Build Command:
cd apps/web && npm install && npm run build - Start Command:
cd apps/web && npm start - Environment:
NEXT_PUBLIC_API_URL=<your-api-url>
Fly.io
Production Considerations
Performance
Enable Python simulation for speed
Enable Python simulation for speed
Ensure Python 3.11+ is installed in your production environment:The Python engine runs 100k simulations in ~500ms vs 3-5 seconds in TypeScript.
Cache simulation results
Cache simulation results
Implement Redis caching for repeated simulations:
Use CDN for static assets
Use CDN for static assets
Vercel automatically serves Next.js static assets via CDN. For other platforms:
- Configure CloudFront or Cloudflare
- Set appropriate cache headers
- Enable compression (gzip/brotli)
Security
Enable CORS properly
Enable CORS properly
In production, restrict CORS to your frontend domain:Set
ALLOWED_ORIGINS=https://drift-production.vercel.app in Railway.Rate limit API endpoints
Rate limit API endpoints
Install and configure rate limiting:
Validate API keys on startup
Validate API keys on startup
Add health checks that verify API connectivity:
Use environment-specific keys
Use environment-specific keys
Maintain separate API keys for each environment:
- Development: Sandbox/test keys with generous rate limits
- Staging: Production keys with test data
- Production: Production keys with real data and strict limits
Monitoring
Monitor API usage
Track API key usage in provider dashboards:
- Gemini: Google AI Studio Console
- ElevenLabs: ElevenLabs Dashboard
- Plaid: Plaid Dashboard
Set up uptime monitoring
Use services like UptimeRobot or Better Uptime to monitor:
- API health endpoint:
https://your-api.com/health - Web app homepage:
https://your-web.com
Scaling
For high-traffic scenarios, consider:
- Horizontal scaling: Run multiple API instances behind a load balancer
- Database: Move from in-memory storage to PostgreSQL for Plaid tokens
- Queue: Use Bull/BullMQ for asynchronous simulation jobs
- Compute: Offload heavy simulations to AWS Lambda or Cloud Functions
Environment Variables Checklist
Before deploying, ensure all required variables are set:- API Server
- Web App
Deployment Checklist
Pre-deployment
- All API keys configured
- Production build successful locally
- Linting passes:
npm run lint - API health check responds
- CORS configured for production domain
Deploy
- API deployed and accessible
- Web app deployed and accessible
- Environment variables set in hosting platform
- API URL updated in web app config
Troubleshooting
CORS errors in production
CORS errors in production
Ensure
ALLOWED_ORIGINS includes your production frontend domain:API key errors
API key errors
Verify environment variables are set in your hosting platform:
Build failures
Build failures
Check build logs for missing dependencies or TypeScript errors:
Slow simulations
Slow simulations
Ensure Python is installed in production environment and NumPy dependencies are met.
Next Steps
Environment Variables
Review all configuration options
API Reference
Explore available endpoints
Performance Tuning
Optimize Monte Carlo simulation performance
API Keys
Configure external service credentials