Debugging and Systematic Troubleshooting Questions
Diagnosing defects methodically: reproducing failures, forming and testing hypotheses, reading stack traces and logs, bisecting changes, and reasoning about error handling and edge cases. Covers a disciplined root-cause approach that applies from local bugs to production issues, distinct from embedded hardware-level debugging. A universally probed engineering-craft skill.
Describe a small but meaningful process or tooling change you introduced that reduced debugging time for your team, for example standardized logs, unit tests for featurization, or pre-commit hooks. Why did you choose that particular change, how did you implement it, and what measurable impact did it have?
Sample Answer
Direct answer
A small, high-leverage change: adding correlation IDs and structured (rather than free-text) logging to a service that previously had neither, so that a failure in one place could actually be traced to its triggering request without manual log archaeology; the choice mattered because it directly attacked the SLOWEST part of the team's existing debugging process, not because it was the most sophisticated tooling available.
Structured elaboration
Why this specific change, not a different one: before proposing anything, the actual bottleneck in the team's debugging process was identified by observation: engineers were regularly spending the first 20-30 minutes of any investigation just correlating free-text log lines across services by eyeballing timestamps, because no shared identifier tied a request's activity together across service boundaries. That specific, repeatedly-observed cost is what made structured logging with a propagated correlation ID the highest-leverage change available, rather than a more sophisticated but less immediately impactful option (like a full distributed-tracing rollout, which would have taken much longer to implement and adopt).
How it was implemented:
- Added a middleware/interceptor at each service's request entry point that either generates a new correlation ID (if the request is the origin) or propagates an incoming one (if it's already present from an upstream caller), attaching it to every log line emitted while handling that request.
- Switched the logging format from free-text to structured (JSON) log lines with consistent field names across services, specifically so the correlation ID (and other common fields) could be queried directly rather than requiring text-pattern matching.
- Rolled it out incrementally, starting with the two or three services most frequently involved in cross-service investigations, rather than attempting a big-bang change across the whole fleet at once, to prove the value and work out format conventions before wider adoption.
Measurable impact: tracked informally at first (asking engineers directly whether recent investigations felt faster) and then more concretely by comparing the TIME-TO-DIAGNOSIS on a sample of incidents before and after rollout for the services that had adopted it; investigations involving those services dropped from a typical 20-30 minutes of manual log correlation to a single structured query pulling the full cross-service trail for a given correlation ID in under a minute, a roughly 20x reduction specifically in the log-correlation phase of debugging (not the whole investigation, which still requires understanding and fixing the actual bug, but the mechanical, previously-wasted part of it).
Trade-offs and pitfalls
The change required upfront work from every team that adopted it (updating their logging calls, agreeing on field-name conventions) and some initial resistance from engineers comfortable with the existing free-text format; the case for adoption was made concrete and low-risk by piloting on a small number of services first and demonstrating the measured time savings, rather than mandating it broadly before it had proven value anywhere.
A recent performance patch reduced average latency but increased p99 latency. How would you investigate and resolve this regression while preserving the average-case gains? Describe your analysis steps and the kinds of code or system fixes you might apply.
Sample Answer
Direct answer
Investigate by looking at the DISTRIBUTION of latencies the patch changed, not just the two summary numbers: a change that helps the median while hurting the tail usually means the patch introduced a new, occasional slow path (a lock, a retry, a cold-cache miss, a GC pause) that wasn't present before, even though it made the common case faster. The fix should target that specific slow path, ideally without giving back the average-case win.
Structured elaboration
- Confirm the shape of the regression with a full latency histogram, not just average and p99 in isolation. Did the whole distribution shift, or did a new secondary "hump" appear at the tail while the bulk of requests got faster? These imply very different causes.
- Look for what the patch changed that could introduce occasional cost. Common culprits: added caching (fast on hit, slow on the now-rarer miss, especially a cold cache after deploy), added batching (fast on average, but a request unlucky enough to wait for a batch to fill sees added latency), a lock or synchronization primitive introduced to make the common path more efficient, or a retry/backoff path that wasn't there before.
- Correlate slow outliers with a specific condition. Pull the individual traces for requests in the new p99 tail and look for what they have in common: a specific input size, a cache miss, contention with a background job, a specific shard or partition.
- Reproduce the tail behavior in isolation once you have a hypothesis, ideally with a small, targeted load test that forces the suspected condition (a cold cache, high concurrency, a large payload) rather than waiting for it to occur naturally in production traffic.
- Fix the specific slow path, not the whole change. The goal is almost never to revert the improvement; it's to bound the cost of the new slow path (a timeout, a smaller batch window, a non-blocking fallback) while keeping the average-case gain.
Worked example
A patch that adds request coalescing (batching several concurrent identical lookups into one backend call) drops average latency by 30% but pushes p99 up by 4x. The latency histogram shows a new cluster of requests waiting close to the full batch window (say, 50ms) even when they were the only request in flight, because the coalescing logic always waits for the window to close before dispatching, even with nothing to batch against. The fix: dispatch immediately if no other request has joined the batch within the first few milliseconds, keeping the win for genuinely concurrent traffic while removing the unnecessary wait for solo requests, which is exactly the group hurting the p99.
Trade-offs and pitfalls
A tempting shortcut is to just revert the patch to restore the old p99, which throws away a real average-case improvement to fix a bug that's usually addressable with a smaller, targeted change. The other trap is chasing the p99 number without ever pulling individual slow traces: two very different mechanisms (a cold-cache path and a lock-contention path) can both show up as "p99 got worse," and the fix for one does nothing for the other.
You receive this Android crash stack trace from a user's device:
FATAL EXCEPTION: main
Process: com.example.app, PID: 12345
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.app.ui.MainActivity.onCreate(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3000)
Identify the most likely root cause, what you would check in the source at that file and line, and two possible fixes.
Sample Answer
Direct answer
The trace shows a NullPointerException at MainActivity.onCreate(MainActivity.java:45) calling setText on a TextView that is null. The most likely root cause: findViewById for that TextView returned null, almost always because setContentView(...) was called with the wrong layout resource (or not called before the findViewById), or the ID referenced doesn't exist in the layout that actually got inflated (a common cause when the app has multiple layout variants, e.g., separate layout and layout-land XML files, and the ID was added to only one).
Structured elaboration
- Check line 45 of
MainActivity.javadirectly to see which view is being set and whichfindViewByIdcall produced it. - Check the order of
setContentViewandfindViewById. IffindViewByIdruns beforesetContentView, or targets a different content view than the one shown, it will returnnullfor every view ID, since there's no inflated view tree yet to search. - Check for layout-variant mismatches. If the app has alternate layout resources for different screen sizes, orientations, or API levels (
res/layout-land,res/layout-sw600dp, etc.), confirm the view ID referenced actually exists in ALL variants that could be inflated at runtime, not just the one the developer was looking at while writing the code. This is one of the most common real-world causes of this exact crash pattern, since it only manifests on devices/configurations that load the variant missing the ID. - Check for a recent layout XML change that renamed or removed the view ID without updating the corresponding
findViewByIdcall, which is a very common source of this bug after a UI refactor. - Confirm the reproduction path. Since this came from a specific user's device (a crash report, not a local repro), check whether the crash correlates with a specific device model, OS version, or locale, any of which could imply a specific layout variant or resource configuration being loaded.
Two possible fixes, addressing the two most likely root causes:
- If
setContentViewwas called with the wrong layout resource: fix the argument to point at the correct layout that actually contains the referenced view ID. - If the view ID genuinely doesn't exist in a particular layout variant (e.g., a landscape-only layout is missing a view present in portrait): either add the missing view to that variant, or guard the code with a null check before calling
setText, if the view is legitimately optional in some layouts.
Worked example
A crash report shows this NPE occurring only on tablet devices; checking the project's resource folders reveals a layout-sw600dp (tablet-specific) variant of the activity's layout that was created for a redesign but never had the TextView with that specific ID added to it, unlike the phone layout. The fix: add the missing view to the tablet layout (or, if it's intentionally absent there, guard the setText call with a null check specific to that code path).
Trade-offs and pitfalls
A defensive null-check around the setText call would stop the crash but silently hides a genuine layout inconsistency, which is the wrong fix if the view was SUPPOSED to exist in every layout variant: the app now fails silently (missing UI element, no visible error) instead of crashing loudly, which is often harder to notice and diagnose later. The null check is the right fix only when the view is deliberately optional in some configurations; otherwise, fix the actual layout/inflation mismatch.
Explain how you would diagnose an Android ANR (Application Not Responding). List the tools and commands you would use, what artifacts you would collect such as traces and stack dumps, and how to interpret a main-thread stack trace to find the blocked operation.
Sample Answer
Direct answer
An ANR (Application Not Responding) fires when the Android system detects the main/UI thread has been blocked too long, typically around 5 seconds for input dispatch (a foreground BroadcastReceiver.onReceive() gets roughly the same 5-second order of magnitude, not a shorter one; a background broadcast gets substantially longer). Diagnosing it means finding what was blocking the main thread at the moment the ANR was triggered, which requires capturing a main-thread stack trace from that exact moment, either from an ANR trace file the system writes, or from a live profiling session if you can reproduce it.
Structured elaboration
- Collect the ANR trace. Android writes a trace file (historically
/data/anr/traces.txt, or accessible viaadb shell dumpsys/ the device's bug report on modern versions) capturing the stack of every thread at the moment of the ANR, most importantly the main thread. Google Play Console also surfaces ANR reports with stack traces for production crashes you can't reproduce locally. - Read the main thread's stack trace specifically. The top frames show exactly what the main thread was doing when it got stuck: a synchronous network call, a large synchronous disk read, a lock wait, or a long-running computation left on the UI thread instead of a background thread.
- Use
adb shell dumpsys activityandAndroid Profiler(CPU profiler, specifically the "trace system calls" or method-tracing mode) to reproduce and observe main-thread activity live if you can trigger the ANR on demand, giving you a timeline rather than just a snapshot. - Check for common ANR causes directly, since certain patterns account for the large majority of real-world ANRs: a network or database call made synchronously on the main thread, a
BroadcastReceiver.onReceive()doing heavy work (its foreground timeout is roughly the same order of magnitude as input dispatch, about 5 seconds per Android's official ANR documentation, not shorter; background broadcasts get a substantially longer allowance, so this cause is just as urgent to rule out as a slow synchronous call), a deadlock between the main thread and a background thread both waiting on each other's locks, or aBindercall to another process that hangs. - Interpret a blocked-on-lock stack correctly. If the main thread's trace shows it waiting on a lock (
BLOCKEDstate in the trace, waiting to enter asynchronizedblock), find which OTHER thread currently holds that lock and what IT is doing; the actual root cause is often in that second thread, not visible directly on the main thread's own stack.
Worked example
An ANR trace shows the main thread's top frame inside SQLiteDatabase.query, called synchronously from onResume(). That's a direct, unambiguous cause: a database query is running on the UI thread, and if the query happens to take longer than usual (a missing index, database growth over time, a device under memory pressure causing disk I/O contention), it now exceeds the ANR threshold. The fix: move the query to a background thread or coroutine, and update the UI once results return, rather than blocking the thread responsible for keeping the app responsive to input.
Trade-offs and pitfalls
The main trap is treating "what was on the main thread's stack" as automatically the fix target, when the trace shows a lock wait: in that case the visible frame is a symptom, and the actual work causing the delay is happening on a different thread entirely, requiring you to read that thread's trace too. A second trap: ANRs that only happen on specific devices or under memory pressure can be very hard to reproduce locally on a fast development device, making production ANR reports (with their bundled stack traces) the primary and sometimes only usable evidence.
Explain, with examples, how cognitive biases such as confirmation bias, anchoring, and sunk-cost fallacy can hinder a debugging investigation. Describe concrete practices, such as pair debugging, rotating investigators, hypothesis logs, and clear acceptance criteria, that you have introduced on a team to mitigate these biases.
Sample Answer
Direct answer
Confirmation bias, anchoring, and sunk-cost fallacy each distort a root-cause investigation in a specific, predictable way: confirmation bias makes you notice evidence supporting your first guess and discount evidence against it; anchoring makes an early, possibly wrong hypothesis dominate the rest of the investigation even after better evidence emerges; and sunk-cost fallacy keeps you investigating a disproven lead because of time already invested in it, rather than switching based on current evidence. Concrete team practices (pair debugging, rotating investigators, hypothesis logs, explicit acceptance criteria) counter each of these by introducing structure that doesn't rely on individual willpower to overcome the bias.
Structured elaboration
Confirmation bias: once you suspect a cause, you unconsciously interpret ambiguous evidence as supporting it and are quicker to dismiss evidence that doesn't fit. In debugging, this looks like reading a log line as "consistent with my theory" when a more neutral read would call it inconclusive, or stopping the investigation the moment ANY supporting evidence appears rather than continuing to look for disconfirming evidence too.
- Mitigation: hypothesis logs. Writing down each hypothesis and what specific evidence would DISCONFIRM it, before looking for evidence, forces a falsifiable framing up front; when you later find evidence, you check it against the pre-written disconfirmation criteria rather than retroactively deciding it "counts" as support.
Anchoring: the first plausible explanation offered (by you, or by someone else on the call) tends to dominate the rest of the investigation's framing, even as better evidence appears, because everyone's mental model has already organized around it.
- Mitigation: rotating investigators / a fresh pair of eyes. Someone joining the investigation LATE, without the accumulated anchor, will naturally form hypotheses from the current evidence rather than the initial framing, and is often the person who notices the anchor was wrong; deliberately bringing in a fresh perspective partway through a long investigation is a structural way to interrupt this.
Sunk-cost fallacy: having spent two hours pursuing one lead makes it psychologically harder to abandon, even once evidence stops supporting it, because abandoning it "wastes" the time already spent (which is, of course, already spent either way, and not actually recoverable by continuing).
- Mitigation: explicit acceptance criteria and timeboxing set in advance. Deciding, BEFORE starting to investigate a specific hypothesis, what evidence would confirm it and how much time is reasonable to spend testing it, makes the "abandon or continue" decision a pre-committed rule rather than an in-the-moment judgment call that sunk cost can distort.
Pair debugging as a mitigation for all three simultaneously: a second person, thinking independently, is less likely to share the exact same anchor or the exact same sunk-cost attachment to a specific lead, and naturally provides a real-time check on confirmation bias by asking "does that evidence actually support that, or are we reading it generously?"
Worked example
A team investigating an intermittent failure anchors early on "it's probably the recent deploy" (a reasonable first guess, given the timing). Two hours in, with the deploy's code reviewed thoroughly and nothing found, sunk cost starts to argue for continuing to scrutinize that same deploy rather than considering it possibly unrelated. A hypothesis log, written at the start, had specified "if the failure recurs on a service instance that predates this deploy, that disconfirms the deploy hypothesis"; checking that specific, pre-committed criterion shows the failure DID recur on an older instance, cleanly disconfirming the deploy theory despite two hours of sunk investigation into it. A rotating fresh investigator, brought in specifically because the original two were stuck, asks a question neither anchored investigator had considered ("what else changed around that time besides the deploy?") and identifies an unrelated infrastructure change that actually explains the failure.
Trade-offs and pitfalls
These practices have a real cost (pairing takes two people's time instead of one; hypothesis logs take a few minutes to write that could otherwise go straight into investigating), and the trade-off is worth it specifically for investigations that are ALREADY taking a long time or where the cost of a wrong conclusion is high; for a five-minute, low-stakes bug, the overhead of formal hypothesis logging isn't proportionate to the risk these biases actually pose in that context.
Unlock Full Question Bank
Get access to all 12 Debugging and Systematic Troubleshooting interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.