Your First Deployment
From local development to global edge deployment in 60 seconds. You’ve built your ensemble. Now let’s put it in production where it matters.Prerequisites
Before deploying:- Wrangler installed and authenticated (
wrangler login) - Working ensemble running locally (
npm run dev) wrangler.tomlconfigured
Deploy to Production
Deployment Checklist
1. Environment Secrets
Never commit secrets to git. Use Wrangler secrets:2. Create Resources
Create required Cloudflare resources:wrangler.toml with the IDs:
3. Run Database Migrations
If using D1, run migrations:4. Deploy Again
Custom Domains
Add Custom Domain
wrangler.toml:
SSL Certificate
Cloudflare automatically provisions SSL certificates. No configuration needed.Multiple Environments
Configure Environments
Editwrangler.toml:
Deploy to Environments
Environment-Specific Secrets
CI/CD Integration
GitHub Actions
Create.github/workflows/deploy.yml:
CLOUDFLARE_API_TOKEN: Create at https://dash.cloudflare.com/profile/api-tokensCLOUDFLARE_ACCOUNT_ID: Find in Cloudflare dashboard
GitLab CI
Create.gitlab-ci.yml:
CLOUDFLARE_API_TOKENCLOUDFLARE_ACCOUNT_ID
Monitoring Deployments
View Logs
Check Metrics
Cloudflare Dashboard
Visit https://dash.cloudflare.com/- Workers & Pages Your worker Metrics
- View:
- Requests per second
- Errors
- CPU time
- Duration
Rollback
Rollback to Previous Deployment
Version Control Rollback
Health Checks
Add health check endpoint:Performance Optimization
Enable Minification
Inwrangler.toml:
Bundle Size
Check bundle size:Caching Headers
Return proper cache headers:Cost Monitoring
Free Tier Limits
- Requests: 100,000/day
- Workers AI: 10,000 neurons/day
- KV Reads: 100,000/day
- KV Writes: 1,000/day
- D1 Rows Read: 5M/day
- D1 Rows Written: 100k/day
Monitor Usage
Check usage in Cloudflare dashboard:- Workers & Pages Analytics
- Set up billing alerts
Optimize Costs
- Cache aggressively - Reduce AI/API calls
- Use KV for caching - Faster and cheaper than D1
- Batch operations - Group D1 writes
- Use Cloudflare AI - Cheaper than OpenAI for simple tasks
- Monitor and optimize - Check analytics regularly
Troubleshooting
Deployment fails with 'binding not found'
Deployment fails with 'binding not found'
Problem: Missing resource bindingFix: Create the resource and add ID to
wrangler.toml500 errors in production
500 errors in production
Problem: Runtime error in workerFix: Check logsLook for stack traces and fix the issue.
Slow cold starts
Slow cold starts
Problem: Large bundle sizeFix: Optimize bundle
AI operations failing
AI operations failing
Problem: Missing AI binding or quota exceededFix:
- Check
wrangler.tomlhas[ai] binding = "AI" - Check usage in Cloudflare dashboard
- Consider paid plan for higher limits

