Debugging in Interviews: A Practical Approach
Interviewers care about your process, not the answer. Learn the structure, the questions to ask, and the habits that signal competence.
By Velloreth
What is being tested
The process, not the answer.
The interviewer wants to see:
- A hypothesis stated before a test
- A test that distinguishes the hypothesis from the alternatives
- A narrowing of the search space
- A clear narration of the state
A candidate who guesses the answer teaches the interviewer nothing.
A candidate who reasons clearly and does not reach the answer still demonstrates the skill.
The opening questions
Ask three questions before reading any code.
| Question | What it eliminates |
|---|---|
| Production or local? | an environment difference |
| Every time or intermittent? | a race, a cache, a load issue |
| What changed recently? | the large majority of causes |
A fourth: how many users are affected, and is it all of them or a subset.
A fifth: is there an error message, and what does the log say.
Asking these is not stalling. It is the first step of the method.
The structure
1. Restate the problem. “So a user updates their profile and the old name still shows for an hour.”
2. State a hypothesis. “I think the cache key is not invalidated on update.”
3. State the test. “I would add a log at the cache write and the cache delete, and check whether the delete fires.”
4. State the expected result. “If the hypothesis is right, the write logs and the delete does not.”
5. Narrow. “If the delete does fire, the problem is in the read path, so I would check the key construction.”
The structure is the answer. The interviewer is watching the sequence.
Narrowing by half
Add a log in the middle of the suspected path.
See which half the failure is in.
Repeat.
A binary search over the code path reaches the cause in a logarithmic number of steps.
The narration:
“The request enters the handler, so the failure is after that. I would log at the service boundary. If the service is reached, the problem is in the service or the database, and if it is not, it is in the handler or the middleware.”
This is the technique an interviewer wants to see, because it is the one that works on an unfamiliar codebase.
The tools
Name the right tool for the symptom.
| Symptom | Tool |
|---|---|
| A wrong value | a log or a breakpoint |
| A slow request | a profiler, a query plan |
| A network failure | the network tab, a proxy |
| A memory growth | a heap snapshot |
| A race | a log with timestamps, a stress test |
| A production-only bug | a structured log, a trace |
Mention the tool briefly. The reasoning is the point.
Being stuck
Say what you know.
Say what you have ruled out.
Say what you would try next.
A candidate who narrates the state is easy to help. A candidate who goes silent is not.
Asking for a hint after a clear summary is not a failure. It is a normal part of the work.
The phrase: “I have ruled out the handler and the middleware. I would look at the service next, and if you have a hint about the area, that would help me focus.”
The habits that signal competence
Stating the expected result before the test. This is what makes it a test.
Saying “I do not know” rather than inventing a mechanism.
Distinguishing a hypothesis from a fact. “I think” versus “I know”.
Considering the boring causes first. A typo, a stale build, a wrong environment, a missing migration.
Checking the assumption. The value that is assumed to be correct is often the bug.
Reading the error message. The whole message, including the part that is scrolled off.
Reproducing before fixing. A fix without a reproduction is a guess.
Writing the test that would have caught it. The fix is not complete without it.
The traps
Guessing the answer. No process is demonstrated.
Silence. The interviewer cannot follow the reasoning.
A test with no expected result. A poke, not a test.
Changing two things at once. The result is uninterpretable.
Ignoring the boring cause. A stale build is more common than a subtle race.
Not reading the error. The answer is often in the message.
Refusing a hint. The interview is a collaboration.
Over-explaining a tool. The reasoning is the point.
Assuming the code is correct. The assumption is often the bug.
Common mistakes
No hypothesis. A random walk.
No expected result. A poke.
Two changes at once. An uninterpretable result.
Silence. No signal.
A complex cause before a simple one. The boring cause is more likely.
No reproduction. A guess.
No test after the fix. The bug returns.
Not asking the opening questions. The search space is not narrowed.
Refusing help. A worse outcome for no benefit.
A quotable summary
A debugging interview tests the process, not the answer: state a hypothesis, state the test and the expected result, and narrow the search space by half at each step. Ask about the environment, the frequency and the recent change before reading any code, name the right tool for the symptom, and narrate the state of the investigation so the interviewer can follow and help. A wrong hypothesis stated clearly is better than silence.
Related reading
For the related topics, see debugging-strategies-that-work and code-reading-strategies. For the broader context, asking-good-technical-questions and learn-programming-without-tutorial-hell.