Backend Developer Interview Question

A query got slow after a release. Walk me through how you read the query plan and decide what to change.

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Run explain analyze to get the real plan with actual row counts and timings, then look for the node consuming the most time and compare estimated rows to actual rows. A big gap means bad statistics, so the planner picked the wrong join or scan. Look for sequential scans on large tables, nested loops driven by an underestimate, and sorts spilling to disk. Fix with an index, updated statistics, or a rewritten predicate that the index can use.

Why interviewers ask this

Any backend developer can add an index; the interviewer is checking whether you diagnose before you do. Reading actual versus estimated rows, spotting an unsargable predicate, and knowing that a sequential scan on a small table is fine are all signs of real database work. It also opens up whether you look at the whole workload, since one query rarely gets slow on its own.

How to structure your answer

  • Get the real plan with explain analyze, not just explain.
  • Find the dominant node and compare estimated to actual rows.
  • Map common patterns to their causes.
  • Verify the fix by measuring the plan again, not by intuition.

Example answer

Spoken example, first person

I start with explain analyze and buffers so I get real timings and row counts, ideally against production sized data because a plan on a small dataset tells me nothing. Then I find the node that owns most of the time and check its estimate against the actual. If it estimated one row and got fifty thousand, the planner chose a nested loop that is now a disaster, and the underlying issue is usually stale statistics or a correlated predicate the planner cannot model. After that I look for the usual suspects: a sequential scan on a big table, a filter that could be an index condition, a sort spilling to disk, or a function wrapped around the column so the index is unusable. That last one was my most recent case, a lower call on an email column that ignored the index; a functional index on lower of email took it from about 900 milliseconds to two. Then I re run the plan to confirm the shape changed, since a faster run on a warm cache proves nothing.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • What makes a predicate unable to use an index?
  • How do you tell a statistics problem from a missing index?
  • When is a sequential scan the right plan?

Related backend developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot