Skip to content
advanced Phase 106 · Incident Response

Failed Deployment

45m
1 problems
Topic Progress 0%

Deployment Failure Overview

Common Failure Types

Failure Types:
├── Build failure
│   ├── Compilation error
│   ├── Dependency conflict
│   └── Test failure
├── Deploy failure
│   ├── Database migration error
│   ├── Permission issue
│   ├── Configuration error
│   └── Service unavailable
├── Post-deploy failure
│   ├── Application error
│   ├── Performance degradation
│   └── Feature broken
└── Rollback failure
    ├── Rollback script failed
    ├── Data inconsistency
    └── Service dependency

Detection

// Monitor deployment metrics
$metrics = [
    'deployment_status' => 'failed',
    'error_rate' => 15, // percent
    'response_time' => 5000, // ms
    'availability' => 95 // percent
];

// Alert on failure
$alerts = [
    'deployment_failed' => [
        'condition' => 'deployment_status == failed',
        'action' => 'page_on_call'
    ],
    'error_spike' => [
        'condition' => 'error_rate > 5',
        'action' => 'notify'
    ]
];

Impact Assessment

// Assess impact
$impact = [
    'affected_users' => $this->getAffectedUsers(),
    'affected_endpoints' => $this->getAffectedEndpoints(),
    'revenue_impact' => $this->calculateRevenueImpact(),
    'sla_breach' => $this->checkSlaBreach()
];

Rollback Procedures

Code Rollback

# Git rollback
git revert HEAD
git push origin main

# Or rollback to specific commit
git revert abc123
git push origin main

# Magento deployment rollback
bin/magento maintenance:enable
bin/magento deploy:mode:set production
bin/magento maintenance:disable

Database Rollback

# Backup before deploy
mysqldump -u root -p magento > backup_$(date +%Y%m%d_%H%M%S).sql

# Rollback migration
bin/magento setup:rollback -r 1234567890

# Or manual rollback
mysql -u root -p magento < backup_20250101_120000.sql

Configuration Rollback

// Restore configuration
public function rollbackConfig()
{
    // Restore from backup
    $backup = $this->configBackup->get('pre_deploy');
    
    foreach ($backup as $key => $value) {
        $this->config->save($key, $value);
    }
    
    // Clear cache
    $this->cache->flush();
}

Service Rollback

# Stop new services
sudo systemctl stop myapp-new

# Start old services
sudo systemctl start myapp-old

# Update load balancer
sudo nginx -t && sudo systemctl reload nginx

Rollback Checklist

□ Confirm decision to rollback
□ Notify team
□ Enable maintenance mode
□ Rollback code
□ Rollback database (if needed)
□ Rollback configuration
□ Clear caches
□ Disable maintenance mode
□ Verify application
□ Monitor metrics
□ Communicate status

Investigation Process

Gather Information

# Check deployment logs
cat /var/log/deploy.log

# Check application logs
tail -f /var/log/magento/exception.log

# Check web server logs
tail -f /var/log/nginx/error.log

# Check database logs
tail -f /var/log/mysql/error.log

# Check recent changes
git log --oneline -10

Analyze Failure

// Common failure analysis
$analysis = [
    'build_failure' => [
        'check' => ['compile_errors', 'test_failures', 'dependency_conflicts'],
        'fix' => ['fix_code', 'fix_tests', 'resolve_dependencies']
    ],
    'deploy_failure' => [
        'check' => ['migration_errors', 'permissions', 'config'],
        'fix' => ['fix_migration', 'fix_permissions', 'fix_config']
    ],
    'runtime_failure' => [
        'check' => ['exceptions', 'performance', 'features'],
        'fix' => ['fix_bug', 'optimize', 'fix_feature']
    ]
];

// Root cause identification
$rootCause = $this->identifyRootCause($failureLogs);

Fix Implementation

// Implement fix
public function implementFix($rootCause)
{
    switch ($rootCause) {
        case 'missing_index':
            $this->addMissingIndex();
            break;
        case 'configuration_error':
            $this->fixConfiguration();
            break;
        case 'code_bug':
            $this->fixCodeBug();
            break;
        case 'dependency_conflict':
            $this->resolveDependency();
            break;
    }
    
    // Test fix
    $this->runTests();
    
    // Deploy fix
    $this->deployFix();
}

Deployment Process Improvement

Pre-deployment Checks

// Automated checks
$checks = [
    'code_quality' => $this->runCodeQuality(),
    'tests' => $this->runTests(),
    'security_scan' => $this->runSecurityScan(),
    'performance_test' => $this->runPerformanceTest(),
    'dependency_check' => $this->checkDependencies()
];

// Fail if any check fails
foreach ($checks as $check) {
    if (!$check['passed']) {
        throw new \Exception('Pre-deployment check failed: ' . $check['name']);
    }
}

Deployment Strategy

// Blue-green deployment
public function blueGreenDeploy()
{
    // 1. Deploy to green (inactive)
    $this->deployToGreen();
    
    // 2. Run smoke tests
    $this->runSmokeTests('green');
    
    // 3. Switch traffic to green
    $this->switchTraffic('green');
    
    // 4. Monitor
    $this->monitor('green');
    
    // 5. Keep blue as rollback
}

// Canary deployment
public function canaryDeploy()
{
    // 1. Deploy to 10% of servers
    $this->deployToCanary(10);
    
    // 2. Monitor metrics
    $metrics = $this->monitorCanary();
    
    // 3. If metrics good, expand
    if ($metrics['error_rate'] < 1) {
        $this->deployToCanary(50);
        $this->deployToCanary(100);
    } else {
        $this->rollbackCanary();
    }
}

Rollback Automation

// Automated rollback
public function autoRollback()
{
    $metrics = $this->getMetrics();
    
    if ($metrics['error_rate'] > 5) {
        $this->rollback();
        $this->alert('Auto-rollback triggered: High error rate');
    }
    
    if ($metrics['response_time'] > 5000) {
        $this->rollback();
        $this->alert('Auto-rollback triggered: High latency');
    }
    
    if ($metrics['availability'] < 99) {
        $this->rollback();
        $this->alert('Auto-rollback triggered: Low availability');
    }
}

Testing Strategy

// Comprehensive testing
$tests = [
    'unit' => $this->runUnitTests(),
    'integration' => $this->runIntegrationTests(),
    'e2e' => $this->runE2eTests(),
    'performance' => $this->runPerformanceTests(),
    'security' => $this->runSecurityTests()
];

// Gate deployment on test results
if ($tests['unit']['failed'] > 0) {
    throw new \Exception('Unit tests failed');
}

if ($tests['integration']['failed'] > 0) {
    throw new \Exception('Integration tests failed');
}

if ($tests['e2e']['failed'] > 0) {
    throw new \Exception('E2E tests failed');
}

Practice Problems

0 / 1 solved
Deployment Failure Response

Deployment failed causing 500 errors on checkout. Need to rollback and investigate.

Solution
// Response:
// 1. Assess: 500 errors on checkout
// 2. Decision: Rollback (critical path)
// 3. Execute: Enable maintenance, rollback, clear cache
// 4. Verify: Checkout working
// 5. Investigate: Check logs, identify cause
// 6. Fix: Address root cause
// 7. Redeploy: With fix
// 8. Prevent: Add to deployment checklist

Quiz

1. What should you do first when deployment fails?

Question 1 options

2. What is blue-green deployment?

Question 2 options

3. What is auto-rollback?

Question 3 options

4. What is the purpose of canary deployment?

Question 4 options

Flashcards

Question

Deployment failure first step?

Answer

Assess impact and decide on rollback

Question

Blue-green deployment?

Answer

Deploy to inactive env, then switch traffic

Question

Canary deployment?

Answer

Test with small traffic before full rollout

Question

Auto-rollback trigger?

Answer

Metrics exceed thresholds (error rate, latency)

Question

Rollback checklist?

Answer

Enable maintenance, rollback, clear cache, verify

Revision Notes

Key Takeaways

  • 1. First: Assess impact, decide rollback vs fix
  • 2. Blue-green: Deploy to inactive, switch traffic
  • 3. Canary: Test with small traffic first
  • 4. Auto-rollback: Triggered by metrics thresholds
  • 5. Checklist: Maintain, rollback, clear, verify

Interview Tips

  • Explain deployment failure handling
  • Discuss rollback procedures
  • Know deployment strategies
  • Understand prevention techniques

Cheat Sheet

Deployment Failure

  • First: Assess impact, decide rollback
  • Blue-green: Inactive env → switch
  • Canary: Small traffic → full rollout
  • Auto-rollback: Metrics thresholds
  • Checklist: Maintain → Rollback → Clear → Verify