Infrastructure Management
Framework for managing infrastructure as code, deployments, and disaster recovery.
Infrastructure as Code (IaC) Best Practices
Principles
Version control everything — All infrastructure configs in Git
Idempotent — Running same config multiple times produces same result
Modular — Reusable modules for common patterns
Documented — README for each module, inline comments for complex logic
Tested — Validate configs before applying (terraform validate, linting)
Workflow
Plan — Review changes, estimate impact
Validate — Run validation/linting
Review — Code review for infrastructure changes
Apply — Deploy in stages (dev → staging → prod)
Verify — Confirm changes work as expected
Document — Update architecture docs
Change Management
Small changes : Direct PR, single reviewer
Medium changes : PR with 2 reviewers, staging test
Large changes : RFC, architecture review, staged rollout
Deployment Strategies
Blue-Green Deployment
Two identical environments : Blue (current), Green (new)
Switch traffic from Blue to Green instantly
Rollback : Switch back to Blue if issues
Pros : Zero downtime, instant rollback
Cons : Requires 2x capacity during deployment
Canary Deployment
Gradual rollout : 5% → 25% → 50% → 100%
Monitor metrics at each stage
Rollback : Stop rollout if metrics degrade
Pros : Risk mitigation, gradual validation
Cons : Slower deployment, requires monitoring
Rolling Deployment
Update instances one at a time
Maintains capacity during rollout
Rollback : Stop rollout, revert remaining instances
Pros : No capacity overhead
Cons : Partial version running, slower rollback
Feature Flags
Toggle features without deployment
Gradual rollout : Enable for % of users
Instant rollback : Disable flag
A/B testing : Compare feature variants
Disaster Recovery Planning
RTO/RPO Definitions
RTO (Recovery Time Objective) : Max acceptable downtime
RPO (Recovery Point Objective) : Max acceptable data loss
Disaster Recovery Template
# Disaster Recovery Plan: {Service/Component}
## RTO/RPO Targets
- **RTO**: {Time} (e.g., 1 hour)
- **RPO**: {Time} (e.g., 15 minutes)
## Failure Scenarios
### Scenario: {Failure Type}
- **Likelihood**: {High/Medium/Low}
- **Impact**: {Description}
- **Detection**: {How to detect}
- **Recovery Steps**:
1. {Step 1}
2. {Step 2}
3. {Step 3}
- **Verification**: {How to verify recovery}
- **Prevention**: {How to prevent}
### Scenario: {Another Failure}
{Repeat structure}
## Backup Strategy
- **Frequency**: {Daily/Hourly/Continuous}
- **Retention**: {Duration}
- **Location**: {Primary/Secondary regions}
- **Verification**: {How backups are tested}
## Recovery Procedures
- **Failover**: {Steps to failover}
- **Failback**: {Steps to failback}
- **Data Restore**: {Steps to restore from backup}
Change Management Checklist
Before making infrastructure changes:
Scaling Playbook
Horizontal Scaling (Scale Out)
When to use:
Stateless services
Need to handle more load
Want redundancy
How:
Add more instances
Load balancer distributes traffic
Auto-scaling based on metrics
Metrics to monitor:
CPU utilization
Request rate
Queue depth
Vertical Scaling (Scale Up)
When to use:
Stateful services (databases)
Single-instance bottlenecks
Memory/CPU limits reached
How:
Increase instance size
More CPU, memory, disk
May require downtime
Metrics to monitor:
CPU utilization
Memory usage
Disk I/O
Auto-Scaling Configuration
Scale-up triggers:
CPU > 70% for 5 minutes
Memory > 80% for 5 minutes
Request rate > threshold
Queue depth > threshold
Scale-down triggers:
CPU < 30% for 15 minutes
Request rate < threshold
Ensure minimum instances maintained
Best practices:
Set min/max instance limits
Use multiple metrics (not just CPU)
Scale up faster than scale down
Test auto-scaling in staging
Infrastructure Review Checklist
Security : Secrets managed, access controls, encryption
Reliability : Redundancy, failover, backups
Performance : Capacity planning, scaling configured
Cost : Right-sized instances, reserved instances, unused resources
Observability : Monitoring, logging, alerting configured
Documentation : Architecture docs, runbooks updated
Compliance : Meets regulatory requirements
Disaster recovery : DR plan tested, RTO/RPO met
1 --- 2 name: infrastructure 3 description: Framework for managing infrastructure as code, deployments, disaster recovery, and scaling. Use when planning infrastructure changes, designing deployments, or responding to capacity issues. 4 --- 5 6 # Infrastructure Management 7 8 Framework for managing infrastructure as code, deployments, and disaster recovery. 9 10 ## Infrastructure as Code (IaC) Best Practices 11 12 ### Principles 13 14 - **Version control everything** — All infrastructure configs in Git 15 - **Idempotent** — Running same config multiple times produces same result 16 - **Modular** — Reusable modules for common patterns 17 - **Documented** — README for each module, inline comments for complex logic 18 - **Tested** — Validate configs before applying (terraform validate, linting) 19 20 ### Workflow 21 22 1. **Plan** — Review changes, estimate impact 23 2. **Validate** — Run validation/linting 24 3. **Review** — Code review for infrastructure changes 25 4. **Apply** — Deploy in stages (dev → staging → prod) 26 5. **Verify** — Confirm changes work as expected 27 6. **Document** — Update architecture docs 28 29 ### Change Management 30 31 - **Small changes**: Direct PR, single reviewer 32 - **Medium changes**: PR with 2 reviewers, staging test 33 - **Large changes**: RFC, architecture review, staged rollout 34 35 ## Deployment Strategies 36 37 ### Blue-Green Deployment 38 39 - **Two identical environments**: Blue (current), Green (new) 40 - **Switch traffic** from Blue to Green instantly 41 - **Rollback**: Switch back to Blue if issues 42 - **Pros**: Zero downtime, instant rollback 43 - **Cons**: Requires 2x capacity during deployment 44 45 ### Canary Deployment 46 47 - **Gradual rollout**: 5% → 25% → 50% → 100% 48 - **Monitor metrics** at each stage 49 - **Rollback**: Stop rollout if metrics degrade 50 - **Pros**: Risk mitigation, gradual validation 51 - **Cons**: Slower deployment, requires monitoring 52 53 ### Rolling Deployment 54 55 - **Update instances** one at a time 56 - **Maintains capacity** during rollout 57 - **Rollback**: Stop rollout, revert remaining instances 58 - **Pros**: No capacity overhead 59 - **Cons**: Partial version running, slower rollback 60 61 ### Feature Flags 62 63 - **Toggle features** without deployment 64 - **Gradual rollout**: Enable for % of users 65 - **Instant rollback**: Disable flag 66 - **A/B testing**: Compare feature variants 67 68 ## Disaster Recovery Planning 69 70 ### RTO/RPO Definitions 71 72 - **RTO (Recovery Time Objective)**: Max acceptable downtime 73 - **RPO (Recovery Point Objective)**: Max acceptable data loss 74 75 ### Disaster Recovery Template 76 77 ```markdown 78 # Disaster Recovery Plan: {Service/Component} 79 80 ## RTO/RPO Targets 81 - **RTO**: {Time} (e.g., 1 hour) 82 - **RPO**: {Time} (e.g., 15 minutes) 83 84 ## Failure Scenarios 85 86 ### Scenario: {Failure Type} 87 - **Likelihood**: {High/Medium/Low} 88 - **Impact**: {Description} 89 - **Detection**: {How to detect} 90 - **Recovery Steps**: 91 1. {Step 1} 92 2. {Step 2} 93 3. {Step 3} 94 - **Verification**: {How to verify recovery} 95 - **Prevention**: {How to prevent} 96 97 ### Scenario: {Another Failure} 98 {Repeat structure} 99 100 ## Backup Strategy 101 - **Frequency**: {Daily/Hourly/Continuous} 102 - **Retention**: {Duration} 103 - **Location**: {Primary/Secondary regions} 104 - **Verification**: {How backups are tested} 105 106 ## Recovery Procedures 107 - **Failover**: {Steps to failover} 108 - **Failback**: {Steps to failback} 109 - **Data Restore**: {Steps to restore from backup} 110 ``` 111 112 ## Change Management Checklist 113 114 Before making infrastructure changes: 115 116 - [ ] **Impact assessment** — What services/components affected? 117 - [ ] **Rollback plan** — How to revert if issues? 118 - [ ] **Testing** — Tested in dev/staging? 119 - [ ] **Documentation** — Runbook updated? 120 - [ ] **Communication** — Stakeholders notified? 121 - [ ] **Monitoring** — Alerts configured for new components? 122 - [ ] **Backup** — Backup/restore tested? 123 - [ ] **Approval** — Required approvals obtained? 124 125 ## Scaling Playbook 126 127 ### Horizontal Scaling (Scale Out) 128 129 **When to use:** 130 - Stateless services 131 - Need to handle more load 132 - Want redundancy 133 134 **How:** 135 - Add more instances 136 - Load balancer distributes traffic 137 - Auto-scaling based on metrics 138 139 **Metrics to monitor:** 140 - CPU utilization 141 - Request rate 142 - Queue depth 143 144 ### Vertical Scaling (Scale Up) 145 146 **When to use:** 147 - Stateful services (databases) 148 - Single-instance bottlenecks 149 - Memory/CPU limits reached 150 151 **How:** 152 - Increase instance size 153 - More CPU, memory, disk 154 - May require downtime 155 156 **Metrics to monitor:** 157 - CPU utilization 158 - Memory usage 159 - Disk I/O 160 161 ### Auto-Scaling Configuration 162 163 **Scale-up triggers:** 164 - CPU > 70% for 5 minutes 165 - Memory > 80% for 5 minutes 166 - Request rate > threshold 167 - Queue depth > threshold 168 169 **Scale-down triggers:** 170 - CPU < 30% for 15 minutes 171 - Request rate < threshold 172 - Ensure minimum instances maintained 173 174 **Best practices:** 175 - Set min/max instance limits 176 - Use multiple metrics (not just CPU) 177 - Scale up faster than scale down 178 - Test auto-scaling in staging 179 180 ## Infrastructure Review Checklist 181 182 - [ ] **Security**: Secrets managed, access controls, encryption 183 - [ ] **Reliability**: Redundancy, failover, backups 184 - [ ] **Performance**: Capacity planning, scaling configured 185 - [ ] **Cost**: Right-sized instances, reserved instances, unused resources 186 - [ ] **Observability**: Monitoring, logging, alerting configured 187 - [ ] **Documentation**: Architecture docs, runbooks updated 188 - [ ] **Compliance**: Meets regulatory requirements 189 - [ ] **Disaster recovery**: DR plan tested, RTO/RPO met