Deployment Strategies
Back to Infrastructure Index
Core Philosophy
The whole point of microservices is to enable teams to develop, deploy and scale independently
Deployment Fundamentals
Artifacts
- Result of things you build
- Can depend on different platform you use
- Can be many formats: Container image, Binary, Jar, etc.
Environment
We can deploy to different environments, each environment serves different purpose:
- Development - For active development
- Staging - Pre-production testing
- Production - Live environment for end users
- QA/Testing - Quality assurance environment
Configuration
- Services need configuration, e.g., Database username and password
- Ideally small amount of configuration
- Different environments also need different config
- Start from small config file, maybe different for each environment
Deployment Risks ⚠️
Deployment can take your prod down
Key Risk Factors
- Capacity - Not enough resources to handle load
- Bad version, Bugs - Code issues in new version
- Statefulness - Data consistency during deployment
- Redundancy - Lack of backup systems
Deployment Strategy Patterns
In the end we can use multiple deployment strategies for your needs
1. In-Place vs Replace
In-Place Deployment
Replace old version in the same server
Pros:
- Fast deployment
- Simple process
Cons:
- Downtime during deployment
- Higher risk
Replace Deployment
Spin up new server with new version
Pros:
- Use load balancer for zero downtime
- Less risk - easy rollback
- Clean separation
Cons:
- Expensive in case of non-cloud infrastructure
- More complex setup
2. All at Once vs Rolling
All at Once
Deploy to all servers simultaneously
Pros:
- Fastest deployment
- Simple coordination
Cons:
- Higher risk
- Full outage if something goes wrong
Rolling Deployment
Deploy gradually to servers in batches
Characteristics:
- Slower deployment speed
- Must consider capacity
- x% or x servers at a time
- Example: 10 servers → (3 - 3 - 3 - 1)
Pros:
- Reduced risk
- Can pause/rollback mid-deployment
- Maintains partial capacity
Cons:
- Longer deployment time
- Mixed versions running temporarily
3. Blue-Green Deployment
Having 2 identical environments, load balancer distributes traffic to appropriate environment
┌─────────────┐
│Load Balancer│
└──────┬──────┘
│
┌───┴───┐
│ │
┌──▼──┐ ┌──▼──┐
│Blue │ │Green│
│(Old)│ │(New)│
└─────┘ └─────┘
Process:
- Blue environment serves production traffic
- Deploy new version to Green environment
- Test Green environment
- Switch traffic to Green
- Keep Blue as backup
Pros:
- Instant rollback
- Zero downtime
- Full testing before switch
Cons:
- Requires double infrastructure
- Cost intensive
4. Canary Deployment
Deploy to small set of users for some period of time
┌─────────────┐
│Load Balancer│
└──────┬──────┘
│
┌───┴────────┐
│ │
┌──▼──┐ ┌──▼──┐
│Old │ │Canary│
│(95%)│ │(5%) │
└─────┘ └─────┘
Process:
- Deploy to small percentage (5-10%)
- Monitor metrics and errors
- Gradually increase traffic
- Full rollout if successful
Pros:
- Early detection of issues
- Minimal user impact
- Data-driven decisions
Cons:
- Complex monitoring required
- Longer deployment time
- Mixed versions for extended period
Deployment vs Release 🔄
Key Concept: We can decouple deployment from release
Definitions
- Deployment - Installing new version of software on production infrastructure
- Release - Serving production traffic to new piece of code
Benefits of Decoupling
- Safety - Deploy without immediately exposing to users
- Testing - Test in production environment safely
- Feature flags - Control feature rollout independently
- Gradual rollout - Progressive exposure to users
Implementation Techniques
- Feature Flags/Toggles
- Dark Launches - Deploy but don’t activate
- A/B Testing - Release to specific user segments
- Ring Deployment - Progressive rings of users
CI/CD Pipeline
Continuous Integration (CI)
Goal: Keep everyone in sync with each other
Key Practices:
- Frequent code commits
- Automated builds
- Automated testing
- Fast feedback loop
Continuous Deployment (CD)
Goal: Get changes to customers and feedback loop from production readiness
Key Practices:
- Automated deployments
- Infrastructure as Code
- Monitoring and alerting
- Rollback procedures
CI/CD Flow
Code → Build → Test → Deploy → Monitor
↑ |
└──────────Feedback────────────┘
Deployment Checklist ✅
Before deploying:
- Automated tests pass
- Code review completed
- Rollback plan ready
- Monitoring configured
- Team notified
- Database migrations tested
- Configuration validated
- Capacity checked
During deployment:
- Monitor error rates
- Check application metrics
- Verify functionality
- Watch user feedback
After deployment:
- Confirm success metrics
- Document any issues
- Update runbooks
- Team retrospective
Best Practices
- Automate Everything - Reduce human error
- Test in Production-like Environments - Catch issues early
- Monitor Actively - Know your system’s health
- Plan for Rollback - Always have an escape route
- Deploy Frequently - Smaller changes = lower risk
- Use Feature Flags - Control releases independently
- Practice Deployments - Make it routine
- Document Procedures - Share knowledge
Related: