Part 5: Capacity Planning and Performance - Growing Without Breaking
The Day My API Fell Over
11:23 - Response times climbing: P95 went from 100ms to 2s
11:27 - Out of memory errors starting
11:31 - Server completely unresponsive
11:34 - Manual restart required
11:36 - Crashes again after 2 minutesUnderstanding Capacity Planning
The Two Types of Capacity Problems
Step 1: Measure Current Capacity
Load Testing with k6
Basic Load Test Script
Interpreting Load Test Results
Spike Testing
Soak Testing
Step 2: Forecasting Future Capacity Needs
Method 1: Linear Trend Analysis
Method 2: Event-Based Planning
Capacity Planning Spreadsheet
Month
Projected Users
Projected RPS
Current Capacity
Utilization
Action Needed
Step 3: Horizontal vs. Vertical Scaling
Vertical Scaling (Scale Up)
Horizontal Scaling (Scale Out)
My Go API: Designed for Horizontal Scaling
Step 4: Performance Optimization with pprof
Enabling pprof in Your Go Application
CPU Profiling
Memory Profiling
Goroutine Profiling
Real Optimization Example
Step 5: Auto-Scaling Strategy
Kubernetes Horizontal Pod Autoscaler (HPA)
Custom Metrics Scaling
Cost-Effective Capacity Planning
Strategy 1: Right-Size Your Baseline
Strategy 2: Auto-Scale for Spikes
Strategy 3: Spot Instances for Non-Critical Work
Strategy 4: Reserved Instances for Baseline
My Capacity Planning Checklist
Real-World Example: Planning for a Product Launch
Common Capacity Planning Mistakes
Mistake 1: Not Load Testing Before Launch
Mistake 2: Scaling Based on CPU/Memory Alone
Mistake 3: No Buffer for Spikes
Mistake 4: Ignoring Database Capacity
Key Takeaways
What's Next
Resources
Conclusion
PreviousPart 4: Incident Management - From Chaos to Coordinated ResponseNextPart 6: Automation and Toil Reduction - Working Smarter, Not Harder
Last updated