Chapter 14: Deployment Architecture
Chapter 14 of 15
Chapter 14: Deployment Architecture
14.1 Deployment Patterns
Deployment patterns define how applications are released to production. Choose patterns based on requirements.
Blue-Green Deployment:
- Run two identical production environments
- Deploy to inactive environment (green)
- Switch traffic from blue to green
- Zero downtime deployment
- Easy rollback
Canary Deployment:
- Deploy new version to small subset of users
- Monitor for issues
- Gradually increase traffic
- Rollback if problems detected
- Lower risk than full deployment
Rolling Deployment:
- Update servers incrementally
- Deploy to subset of servers
- Gradually update remaining servers
- Maintains service availability
Feature Flags:
- Deploy code with features disabled
- Enable features via configuration
- Test in production safely
- Quick rollback by disabling flag
14.2 CI/CD Pipelines
CI/CD (Continuous Integration/Continuous Deployment) automates testing and deployment processes.
Continuous Integration (CI):
- Automatically test code on commit
- Run unit and integration tests
- Check code quality
- Build application
- Provide feedback quickly
Continuous Deployment (CD):
- Automatically deploy to production
- After successful CI pipeline
- Reduces manual deployment errors
- Faster release cycles
# CI/CD Pipeline Example (.github/workflows/deploy.yml)
name: Deploy
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Build
run: npm run build
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- name: Deploy to production
run: ./deploy.sh
CI/CD Tools:
- GitHub Actions: Built into GitHub
- GitLab CI: Integrated with GitLab
- Jenkins: Self-hosted automation
- CircleCI: Cloud-based CI/CD
- AWS CodePipeline: AWS-native pipeline
14.3 Containerization
Containers package applications with dependencies for consistent deployment.
Docker:
- Containerization platform
- Consistent environments
- Easy deployment
- Isolation from host system
# Dockerfile example
FROM node:16
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
Container Orchestration:
- Kubernetes: Container orchestration
- Docker Swarm: Docker-native orchestration
- ECS: AWS container service
14.4 Monitoring and Rollback
Monitor deployments and have rollback strategies ready.
- Monitor application health after deployment
- Track error rates and performance metrics
- Set up alerts for issues
- Maintain previous version for quick rollback
- Test rollback procedures