The database CPU is at 95% and the API is timing out. What's your approach?
IntermediateScenarioScaling and performance
Answer
Situation read → The DB is the shared bottleneck; scaling app pods will make it worse by adding connections and queries.
What I'd do →
- Find the expensive queries: RDS Performance Insights top SQL, or in Postgres:
SELECT query, calls, mean_exec_time, total_exec_time
FROM pg_stat_statements ORDER BY total_exec_time DESC LIMIT 10;
- Check for a recent deploy that added a query or dropped an index.
- Quick wins: kill runaway queries (
pg_terminate_backend), add a missing index (CREATE INDEX CONCURRENTLY), cap the app's HPA so it stops piling on connections. - Shed load: disable non-critical features, move reads to a replica, add caching for hot reads.
- Short-term scale-up of the instance class if needed (Multi-AZ makes this a brief failover).
Why → In most DB CPU incidents one or two queries cause most of the load; fix those before buying hardware.
Interview tip → Say "scaling app pods can make a DB problem worse".
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?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?AdvancedOne pod in a deployment is much slower than the others. How do you investigate?Beginner