Rollback Instructions
Rollback Instructions
Overview
This document provides procedures for rolling back deployments in the Learnille platform. Rollbacks may be necessary due to application failures, performance issues, or other critical problems.
Rollback Types
1. Automated Rollback
- Trigger: Health check failures, error thresholds exceeded
- Execution: Immediate, no manual intervention required
- Duration: < 5 minutes
- Scope: Application container rollback
2. Manual Rollback
- Trigger: Detected issues requiring human judgment
- Execution: Manual command execution
- Duration: 10-30 minutes
- Scope: Application, database, or infrastructure
3. Emergency Rollback
- Trigger: Critical system failure, security breach
- Execution: Immediate action by on-call engineer
- Duration: < 15 minutes
- Scope: Complete environment restoration
Pre-Rollback Checklist
Assessment
- Identify the issue and impact
- Determine rollback scope (application, database, infrastructure)
- Check current system status and monitoring
- Notify stakeholders if needed
- Gather evidence (logs, metrics, user reports)
Preparation
- Verify backup availability and integrity
- Check previous version stability
- Prepare rollback commands/scripts
- Ensure access to deployment tools
- Coordinate with team members if needed
Automated Rollback Procedures
Application Rollback (Kubernetes)
Immediate Rollback
# Check current deployment statuskubectl get deployments -n learnille-prod
# Rollback to previous revisionkubectl rollout undo deployment/learnille-api -n learnille-prod
# Monitor rollback progresskubectl rollout status deployment/learnille-api -n learnille-prodBlue-Green Rollback
# Check which environment is activekubectl get service learnille-api -n learnille-prod -o yaml
# Switch traffic back to blue environmentkubectl patch service learnille-api -n learnille-prod -p '{"spec":{"selector":{"version":"blue"}}}'
# Verify traffic switchkubectl get endpoints learnille-api -n learnille-prodDatabase Rollback
Migration Rollback
# Check migration statusnpm run migration:status -- --env production
# Rollback last migrationnpm run migration:rollback -- --env production
# Verify database integritynpm run migration:status -- --env productionData Restore (if needed)
# Restore from backup (if data corruption)pg_restore -h production-db -U learnille -d learnille_prod backup_file.sql
# Verify data integritypsql -h production-db -U learnille -d learnille_prod -c "SELECT COUNT(*) FROM users;"Manual Rollback Procedures
1. Application Rollback
Self-Hosted PM2 / Git Rollback
# SSH into self-hosted production serverssh admin@server.learnille.dev
# Navigate to application rootcd /opt/learnille
# Checkout previous stable Git commit / taggit checkout v1.2.0
# Rebuild and reload PM2 processcd server && npm install && npm run buildpm2 reload learnille-api --update-env—service learnille-api
—task-definition learnille-api:1.2.2
—force-new-deployment
Monitor deployment
aws ecs describe-services
—cluster learnille-prod
—services learnille-api
—query ‘services[0].deployments’
#### Using Docker Compose```bash# Stop current containersdocker-compose -f production.yml down
# Update image version in compose filesed -i 's/learnille\/api:1.2.3/learnille\/api:1.2.2/' production.yml
# Start previous versiondocker-compose -f production.yml up -d
# Verify containersdocker-compose -f production.yml ps2. Infrastructure Rollback
Terraform Rollback
# Check current stateterraform show
# Rollback to previous stateterraform plan -state=terraform.tfstate.backupterraform apply -state=terraform.tfstate.backup
# Verify infrastructureterraform showCloudFormation Rollback
# Check stack statusaws cloudformation describe-stacks --stack-name learnille-prod
# Rollback to previous versionaws cloudformation update-stack \ --stack-name learnille-prod \ --template-body file://template-v1.2.2.yaml \ --parameters file://parameters.json
# Monitor stack updateaws cloudformation describe-stack-events --stack-name learnille-prod3. Configuration Rollback
Environment Variables
# Backup current environmentcp .env.production .env.production.backup
# Restore previous environmentcp .env.production.v1.2.2 .env.production
# Restart applicationkubectl rollout restart deployment/learnille-api -n learnille-prodConfiguration Files
# Backup current configcp config/production.yaml config/production.yaml.backup
# Restore previous configcp config/production-v1.2.2.yaml config/production.yaml
# Apply configurationkubectl apply -f config/production.yamlEmergency Rollback Procedures
Critical System Failure
-
Immediate Assessment
Terminal window # Check system statuscurl -f https://api.learnille.com/health || echo "API down"# Check database connectivitypsql -h production-db -U learnille -d learnille_prod -c "SELECT 1;"# Check infrastructure statusaws ecs describe-services --cluster learnille-prod --services learnille-api -
Execute Emergency Rollback
Terminal window # Force rollback to last known good statekubectl set image deployment/learnille-api app=learnille/api:1.2.2 -n learnille-prodkubectl rollout status deployment/learnille-api -n learnille-prod# Switch to backup database if neededaws rds failover-db-cluster --db-cluster-identifier learnille-prod -
Traffic Management
Terminal window # Enable maintenance modekubectl patch configmap learnille-config -p '{"data":{"maintenance":"true"}}'# Switch to backup load balanceraws elbv2 set-ip-address-type \--load-balancer-arn $BACKUP_LB_ARN \--ip-address-type ipv4
Security Incident Response
-
Isolate Affected Systems
Terminal window # Block suspicious trafficaws waf update-ip-set \--name suspicious-ips \--scope REGIONAL \--id $IP_SET_ID \--addresses $SUSPICIOUS_IP# Disable compromised servicekubectl scale deployment learnille-api --replicas=0 -n learnille-prod -
Data Recovery
Terminal window # Restore from clean backupaws s3 cp s3://learnille-backups/clean-backup.sql /tmp/psql -h production-db -U learnille -d learnille_prod < /tmp/clean-backup.sql -
Security Validation
Terminal window # Run security scandocker run --rm -v $(pwd):/src securecodebox/scanner# Update security groupsaws ec2 revoke-security-group-ingress --group-id $SG_ID --protocol tcp --port 80 --cidr 0.0.0.0/0
Post-Rollback Procedures
Validation Steps
- Application health checks passing
- Database connectivity verified
- User functionality tested
- Performance metrics normal
- Monitoring alerts cleared
Documentation
# Document rollback in incident logecho "$(date): Rollback executed - $(whoami)" >> rollback-log.txtecho "Reason: $ROLLBACK_REASON" >> rollback-log.txtecho "Impact: $ROLLBACK_IMPACT" >> rollback-log.txt
# Update status pagecurl -X POST https://status.learnille.com/api/incidents \ -H "Authorization: Bearer $STATUS_API_KEY" \ -d '{"status": "resolved", "message": "Issue resolved via rollback"}'Communication
- Notify internal team via Slack
- Update external status page
- Send customer communication if needed
- Schedule post-mortem meeting
Investigation
- Analyze root cause of deployment failure
- Review monitoring data during incident
- Update deployment processes if needed
- Document lessons learned
Monitoring During Rollback
Key Metrics to Monitor
- Application response time
- Error rates by endpoint
- Database connection pool usage
- Infrastructure resource utilization
- User session success rate
Alerting During Rollback
# Temporary rollback monitoringgroups: - name: rollback-monitoring rules: - alert: RollbackHealthCheck expr: up{job="learnille-api"} == 0 for: 2m labels: severity: critical rollback: "true" - alert: RollbackErrorRate expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.1 for: 5m labels: severity: critical rollback: "true"Rollback Testing
Regular Testing
- Monthly rollback drills
- Automated rollback testing in staging
- Documentation review and updates
- Team training sessions
Test Scenarios
- Application deployment failure
- Database migration failure
- Infrastructure configuration error
- Security vulnerability discovery
- Performance degradation
Tools and Resources
Rollback Scripts
#!/bin/bashset -e
echo "Starting emergency rollback..."
# Get last stable versionSTABLE_VERSION=$(curl -s https://api.github.com/repos/learnille/learnille/releases/latest | jq -r .tag_name)
# Execute rollbackkubectl set image deployment/learnille-api app=learnille/api:$STABLE_VERSIONkubectl rollout status deployment/learnille-api
echo "Rollback completed successfully"Monitoring Dashboard
- Rollback status dashboard
- Real-time metrics during rollback
- Historical rollback data
- Success/failure analytics
Contact Information
Emergency Contacts
- Primary On-call: +1-555-0123 (DevOps Engineer)
- Secondary On-call: +1-555-0124 (Senior Engineer)
- Management: +1-555-0125 (Engineering Manager)
Communication Channels
- Slack: #incidents
- Email: incidents@learnille.com
- Status Page: https://status.learnille.com
- Runbook Repository: https://github.com/learnille/runbooks
Continuous Improvement
Metrics Tracking
- Rollback frequency and success rate
- Mean time to rollback
- Customer impact assessment
- Process efficiency improvements
Process Updates
- Regular review of rollback procedures
- Incorporation of lessons learned
- Tool and automation improvements
- Team training and preparedness