Runbook: Gateway Scaling¶
Overview¶
The Gateway service handles all API requests and orchestrates run execution. This runbook covers scaling procedures for various scenarios.
Metrics to Monitor¶
| Metric | Threshold | Action |
|---|---|---|
| CPU utilization | > 70% for 5min | Scale up |
| Memory utilization | > 75% for 5min | Scale up |
| Request latency p99 | > 500ms | Scale up |
| Error rate | > 1% | Investigate, possibly scale |
| Request queue depth | > 100 | Scale up |
Horizontal Scaling¶
Kubernetes (Automatic via HPA)¶
The HPA handles automatic scaling. Check current status:
Manual Scaling¶
If HPA is insufficient or disabled:
# Scale to specific replica count
kubectl scale deployment gateway -n ferrumdeck-prod --replicas=10
# Verify pods are ready
kubectl get pods -n ferrumdeck-prod -l app.kubernetes.io/name=gateway
Docker Compose¶
Vertical Scaling¶
If horizontal scaling doesn't help (e.g., memory pressure):
-
Update resource limits in overlay:
-
Apply and trigger rolling update:
Pre-Scaling Checklist¶
Before scaling up, verify:
- [ ] PostgreSQL connection pool has headroom (max_connections)
- [ ] Redis has sufficient memory for more connections
- [ ] Load balancer health checks are passing
- [ ] No ongoing deployment or incident
Post-Scaling Verification¶
After scaling:
-
Check all pods healthy:
-
Verify load distribution:
-
Monitor for 10 minutes:
- Error rate should decrease or stay stable
- Latency should improve
- No pod restarts
Scaling Down¶
Scale down gradually during low-traffic periods:
-
Set HPA minReplicas lower:
-
Allow HPA to scale down naturally (wait stabilization period)
-
Never scale below minAvailable in PDB (2 for gateway)
Troubleshooting¶
Pods not scaling up¶
- Check HPA events:
kubectl describe hpa gateway-hpa - Check metrics-server:
kubectl top pods -n ferrumdeck-prod - Check node capacity:
kubectl describe nodes | grep -A5 "Allocated resources"
Pods failing to start¶
- Check events:
kubectl get events -n ferrumdeck-prod --sort-by='.lastTimestamp' - Check logs:
kubectl logs -n ferrumdeck-prod <pod-name> --previous
Performance not improving after scale¶
- Check database connection pool saturation
- Check Redis memory/CPU
- Profile application for bottlenecks