Database Concurrency & Scaling interview question · Most asked

Database CPU is at 85%. How do you decide what to optimise before buying a bigger server?

Summary

Rank statements by total time (calls × mean) using pg_stat_statements or performance_schema digests, fix the top entries (indexes, N+1, pagination), and verify with EXPLAIN ANALYZE — usually far cheaper than scaling hardware.

Longer Answer

The slowest single query is rarely the biggest load; a 30 ms query called millions of times usually is. Look at calls per request too (N+1), and compare estimated vs actual rows in plans for statistics problems. Then consider caching and read replicas for what remains.

Key Points

  • Optimise by total time
  • pg_stat_statements / performance_schema
  • Verify with EXPLAIN ANALYZE
  • Hardware last

Deep dive: Finding the Queries That Matter

More most-asked Database Concurrency & Scaling questions

← All Database Concurrency & Scaling questions