How do you decide between vertical and horizontal scaling for a service?
BeginnerScenarioScaling and performance
Answer
Situation read → It depends on whether the workload can be split across instances.
What I'd do →
- Stateless web and API tiers: horizontal. More pods behind a load balancer, autoscaled by HPA.
- Single-writer stateful systems (a primary DB): vertical first, then read replicas, then sharding as a last resort.
- Workloads that need lots of memory per unit (big in-memory models, caches): vertical, or shard by key.
- Use VPA in recommendation mode to right-size requests, and HPA to handle load changes. Don't let both act on CPU for the same deployment.
Why → Horizontal scaling also gives redundancy; vertical scaling has a ceiling and often needs a restart.
Interview tip → Mention the VPA and HPA conflict on the same metric.
More on Scaling and performance
Traffic is expected to 10x for a sale next week. How do you prepare the platform?IntermediateThe HPA is configured but pods don't scale even though the app is slow. Why?BeginnerPods are Pending during a traffic spike because the cluster is out of capacity. What do you do now and long term?IntermediateThe database CPU is at 95% and the API is timing out. What's your approach?Intermediate"Too many connections" errors from Postgres after scaling the app out. How do you fix it?IntermediateLatency is fine on average but p99 is terrible. Where do you look?Advanced