Start from the queries, not the table. Look at what appears in WHERE, JOIN and ORDER BY, then build a composite index with the equality columns first and the range or sort column last. Confirm with EXPLAIN ANALYZE that an index scan replaced a sequential scan. Every index costs write throughput and storage, so drop unused ones and avoid indexing a low cardinality column on its own.
Why interviewers ask this
Indexing is the highest leverage database skill a full stack developer can have, and it is easy to fake until someone asks about column order. The interviewer wants to know whether you read query plans, whether you understand that indexes are a write tax and not free speed, and whether you would notice that adding an index per column is a common and expensive mistake.
How to structure your answer
- Say that indexes follow the query patterns, not the schema.
- Explain composite index column ordering.
- Describe how you verify with the query plan.
- Name the cost side: writes, storage, unused indexes.
Example answer
I work backwards from the slow query log rather than guessing at design time. Take a query filtering on tenant id and status and sorting by created at. The right index there is on tenant id, status, created at in that order, because equality predicates go first and the sort column goes last so the index can satisfy the ordering too. Put created at first and the index is nearly useless for that query. Then I actually run EXPLAIN ANALYZE and check the plan changed and the row estimates are sane, because the planner will ignore an index if it thinks it will match most of the table anyway. On the cost side, I have seen a write heavy table with eleven indexes where inserts were the bottleneck, and dropping four unused ones roughly doubled ingest throughput. In Postgres I check pg_stat_user_indexes for indexes with zero scans before proposing anything gets dropped, and I create them concurrently on a live table.
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 worksFollow-up questions to expect
- What is a covering index and when does it help?
- Why might the planner ignore an index you just added?
- When would you use a partial index instead?
Related full stack 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