Interview Prep/Real-World Interview/Scaling and performance

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 →

  1. 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;
  1. Check for a recent deploy that added a query or dropped an index.
  2. 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.
  3. Shed load: disable non-critical features, move reads to a replica, add caching for hot reads.
  4. 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".

All Real-World Interview questions Roadmap: Interview readiness

More on Scaling and performance