Skip to main content

Deployment Best Practices

Comprehensive guidelines for deploying applications safely and efficiently.

Overview

Deployment best practices ensure reliable, secure, and efficient application releases with minimal downtime and risk.

Purpose: Safe and efficient deployments
Owner: DevOps & Development Teams


Core Deployment Principles

Deployment Fundamentals

  1. Automate Everything: Automated deployments reduce errors
  2. Test Thoroughly: Test before deploying
  3. Deploy Incrementally: Gradual rollouts reduce risk
  4. Monitor Continuously: Watch for issues
  5. Rollback Ready: Always have rollback plan
  6. Document Everything: Clear deployment documentation

Pre-Deployment

Preparation Checklist

Code Ready:

  • All tests passing
  • Code reviewed
  • No known bugs
  • Dependencies updated
  • Security scanned

Environment Ready:

  • Staging tested
  • Database migrations ready
  • Environment variables set
  • SSL certificates valid
  • DNS configured

Team Ready:

  • Deployment plan reviewed
  • Team notified
  • Rollback plan ready
  • Monitoring configured
  • Support team briefed

Deployment Strategies

Blue-Green Deployment

Process:

  1. Deploy to green environment
  2. Test green environment
  3. Switch traffic to green
  4. Keep blue as backup

Advantages:

  • Zero downtime
  • Easy rollback
  • Full testing before switch

Canary Deployment

Process:

  1. Deploy to small subset (5-10%)
  2. Monitor metrics
  3. Gradually increase traffic
  4. Full rollout if successful

Advantages:

  • Reduced risk
  • Early issue detection
  • Gradual rollout

Rolling Deployment

Process:

  1. Deploy to one server
  2. Test and monitor
  3. Deploy to next server
  4. Repeat until complete

Advantages:

  • No downtime
  • Gradual rollout
  • Resource efficient

Deployment Process

Step 1: Pre-Deployment

Final Checks:

# Run tests
npm test

# Build application
npm run build

# Security scan
npm audit

# Lint code
npm run lint

Backup:

  • Database backup
  • Code backup
  • Configuration backup
  • Media files backup

Step 2: Database Migrations

Migration Best Practices:

  • Test migrations on staging
  • Backward compatible
  • Rollback scripts ready
  • Backup before migration

Example:

# Backup database
pg_dump database > backup.sql

# Run migrations
npm run migrate

# Verify migrations
npm run migrate:status

Step 3: Application Deployment

Deployment Steps:

# 1. Pull latest code
git pull origin main

# 2. Install dependencies
npm ci --production

# 3. Build application
npm run build

# 4. Run migrations
npm run migrate

# 5. Restart application
pm2 restart app

# 6. Verify deployment
curl https://yourapp.com/health

Step 4: Post-Deployment

Verification:

  • Application running
  • Health checks passing
  • Key features working
  • No errors in logs
  • Monitoring active

Monitoring:

  • Error rates
  • Response times
  • CPU/Memory usage
  • Database performance
  • User activity

Environment Management

Environment Types

Development:

  • Local development
  • Frequent changes
  • Debug enabled
  • Test data

Staging:

  • Production-like
  • Pre-release testing
  • Real-like data
  • Performance testing

Production:

  • Live environment
  • Optimized
  • Monitored
  • Backed up

Environment Variables

Best Practices:

  • Never commit secrets
  • Use environment files
  • Different per environment
  • Document all variables

Example (.env):

# Application
NODE_ENV=production
PORT=3000

# Database
DB_HOST=localhost
DB_NAME=myapp
DB_USER=dbuser
DB_PASS=securepassword

# API Keys
API_KEY=your_api_key
SECRET_KEY=your_secret_key

CI/CD Pipeline

Continuous Integration

CI Pipeline:

# .github/workflows/ci.yml
name: CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Run linter
run: npm run lint
- name: Security audit
run: npm audit

Continuous Deployment

CD Pipeline:

# .github/workflows/deploy.yml
name: Deploy

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy to production
run: |
npm ci
npm run build
npm run deploy

Rollback Procedures

When to Rollback

Rollback If:

  • Critical bugs discovered
  • Performance degradation
  • Security issues
  • Data corruption
  • User-facing errors

Rollback Process

Quick Rollback:

# 1. Switch to previous version
git checkout previous-tag

# 2. Rebuild
npm run build

# 3. Restart
pm2 restart app

# 4. Verify
curl https://yourapp.com/health

Database Rollback:

# Restore database backup
pg_restore -d database backup.sql

# Or run rollback migrations
npm run migrate:rollback

Monitoring & Alerts

Key Metrics

Application Metrics:

  • Response time
  • Error rate
  • Request rate
  • Success rate

Infrastructure Metrics:

  • CPU usage
  • Memory usage
  • Disk space
  • Network traffic

Business Metrics:

  • Active users
  • Conversions
  • Revenue
  • Key features usage

Alert Configuration

Critical Alerts:

  • Application down
  • Error rate > 5%
  • Response time > 3s
  • Database down

Warning Alerts:

  • CPU > 80%
  • Memory > 80%
  • Disk space < 20%
  • Error rate > 1%

Security Best Practices

Deployment Security

Secure Deployments:

  • Use SSH keys
  • Encrypt secrets
  • Limit access
  • Audit deployments
  • Scan for vulnerabilities

Secret Management:

  • Use secret managers
  • Rotate secrets regularly
  • Never commit secrets
  • Encrypt at rest
  • Limit access

Deployment Checklist

Pre-Deployment:

  • All tests passing
  • Code reviewed
  • Staging tested
  • Backup completed
  • Team notified
  • Rollback plan ready

Deployment:

  • Deploy to staging first
  • Run migrations
  • Deploy application
  • Verify deployment
  • Monitor metrics

Post-Deployment:

  • Health checks passing
  • No errors in logs
  • Key features working
  • Monitoring active
  • Team notified
  • Documentation updated

Common Issues

Issue 1: Deployment Fails

Solutions:

  • Check logs
  • Verify dependencies
  • Check permissions
  • Verify configuration

Issue 2: Application Won't Start

Solutions:

  • Check environment variables
  • Verify database connection
  • Check port availability
  • Review error logs

Issue 3: Performance Degradation

Solutions:

  • Check resource usage
  • Review recent changes
  • Monitor database
  • Check external services

Tools & Resources

Deployment Tools:

  • GitHub Actions
  • GitLab CI/CD
  • Jenkins
  • CircleCI

Monitoring:

  • New Relic
  • Datadog
  • Sentry
  • LogRocket

Infrastructure:

  • AWS
  • Google Cloud
  • Azure
  • DigitalOcean

Last Updated: January 2026
Version: 1.0
Owner: ARUKZ DIGITAL DevOps Team


Related Documentation: