IntermediateTECHNICAL
You notice that a frequently used query is causing high CPU usage on the database server. How would you analyze and optimize this query? Be specific about the steps and tools you’d use (e.g., EXPLAIN plans, indexing strategies).
Backend Developer
General

Sample Answer

When I see a hot query pegging DB CPU, I start by confirming it’s actually the culprit: I’ll look at pg_stat_statements or the slow query log to see call frequency, average latency, and total CPU time. Once I’ve isolated the query, I run EXPLAIN (and EXPLAIN ANALYZE in staging) to understand the plan: full table scans, bad join order, misused indexes, etc. On one service with ~200 queries/sec, a reporting query was doing a sequential scan over 20M rows. By adding a composite index on (account_id, created_at) and rewriting the WHERE clause to match the index order, we cut that query from ~1.8s to ~40ms and dropped DB CPU by about 35%. I also checked for N+1 patterns in the app layer and added a read replica dedicated to heavy reports so OLTP traffic stayed healthy.

Keywords

Use of pg_stat_statements/slow query logs to identify real hotspotsEXPLAIN/EXPLAIN ANALYZE to inspect query plans and spot full scans or bad joinsTargeted index design (composite, covering) and query rewritesConsideration of application patterns and replicas, not just DB-level tweaks
Related Questions

In your civil engineering studies, what specific design coursework or project work did you complete related to irrigation channels or canals (e.g., design of lined/unlined canals, distributaries, minors)? Describe one such design in detail, including how you determined discharge, permissible velocity, section dimensions, and lining choice for Gujarat-type soil and climate conditions.

IntermediateTECHNICAL

Based on your hydrology and irrigation engineering background, explain how you would estimate the irrigation water requirement for a kharif crop in a semi-arid region of Gujarat. Walk me through each step: from reference evapotranspiration estimation, crop coefficient selection, effective rainfall calculation, to arriving at canal discharge for a given command area.

IntermediateTECHNICAL

Walk me through a recent multi-channel digital marketing campaign you managed end-to-end. How did you set objectives, choose channels, allocate budget, and measure success?

IntermediateBEHAVIORAL

In your resume you note improving or optimizing [a process, KPI, or metric]. What specific baseline metrics did you start from, what steps did you personally take, and how did you verify that the improvement was due to your changes rather than external factors?

IntermediatePROBLEM_SOLVING

On your resume you mention working on a cross-functional project (e.g., involving multiple teams or stakeholders). Describe a situation from that project where priorities conflicted—how did you navigate the trade-offs and what was the final outcome?

IntermediateSITUATIONAL