This document describes how to roll back a Cloudflare Worker deployment using Wrangler CLI.
# List recent deployments
wrangler deployments list
# Rollback to previous version
wrangler rollback
# Rollback to specific version
wrangler rollback --version <deployment-id>Rollback should be performed when:
- A production deployment causes critical errors
- API endpoints are returning unexpected errors
- The Worker is unresponsive or timing out
- A security vulnerability is discovered in deployed code
- Verify the issue: Confirm the issue is caused by the recent deployment, not an external dependency
- Check deployment history: Review recent deployments to identify the stable version
- Notify team: Alert relevant team members about the rollback
- Document the issue: Record what went wrong for post-mortem
# List recent deployments for production
wrangler deployments list
# For staging environment
wrangler deployments list --env stagingExample output:
┌─────────────────────────────────────────────────────────────────────────────┐
│ Deployment ID: 373305c6-56f3-4fc7-8540-1e1e1e1e1e1e │
│ Created on: 2024-03-15T10:30:00.000000Z │
│ Author: ci-user │
│ Source: Upload │
│ Version: 1.2.3 │
└─────────────────────────────────────────────────────────────────────────────┘
Find the deployment ID of the stable version you want to roll back to. This is typically the deployment immediately before the problematic one.
# Rollback to the most recent previous deployment
wrangler rollback
# Or specify a specific deployment
wrangler rollback --version <deployment-id>
# For staging environment
wrangler rollback --env staging --version <deployment-id># Check deployment status
wrangler deployments list
# Test the worker endpoint
curl https://spikes.sh/health
# Check logs for errors
wrangler tail --format json- Monitor: Watch logs for any issues
- Fix the issue: Address the root cause in a branch
- Test thoroughly: Ensure the fix works in staging
- Re-deploy: Create a new deployment with the fix
# Production uses the default environment or --env production
wrangler rollback
# or
wrangler rollback --env productionwrangler rollback --env stagingIMPORTANT: Rollback only affects the Worker code, not the D1 database.
If a deployment included schema migrations:
- Do NOT rollback the Worker if the migration cannot be reversed
- Create a forward-fix migration instead
- If the migration is reversible, run the down migration first:
# Apply down migration (if available)
wrangler d1 execute spikes-sh-db --file=migrations/down.sqlWorker rollback does not affect R2 bucket contents. If assets were corrupted:
- Restore from backup if available
- Re-upload correct assets:
# Re-upload widget
wrangler r2 object put spikes-hosted-assets/widget/spikes.js \
--file public/spikes.js --content-type application/javascriptIf rollback fails or you need assistance:
- Check Cloudflare status page
- Review Cloudflare dashboard for alerts
- Contact Cloudflare support if the issue is platform-related
After rollback, ensure the git repository reflects the correct state:
# Tag the current stable version if not already tagged
git tag -a v1.2.2-stable -m "Stable version after rollback"
# Create a branch from the stable version for the fix
git checkout -b fix/deployment-issue v1.2.2-stableAfter an emergency rollback, the next push to main will trigger a new staging deployment. To prevent re-deploying the broken version:
- Fix the issue in a branch
- Test in staging
- Merge to main
- Create a new release tag for production
After rollback, monitor for:
- Error rates in Worker logs (
wrangler tail) - Response times from health endpoints
- User reports of issues
- Stripe webhook delivery status
- D1 query performance