Debug Like a Scientist - hero image
Blog - Debugging Workflow - Frontend and Backend

Debug Like a Scientist - A Practical Workflow

Debugging is not magic. It is a controlled experiment. The goal is not to stare harder at code - it is to reduce uncertainty fast, isolate the cause, and ship a fix that does not come back to haunt you.

Published - -
Last updated - -

What most people do wrong

Most debugging fails because of one classic sin - changing multiple things at once. That turns your system into a fog machine. The fix looks random because it basically was.

Rule - One hypothesis at a time. One change at a time. Otherwise you are not debugging - you are gambling.

The 6 step workflow

1 - Reproduce reliably
Make it repeatable

Write the shortest set of steps that triggers the bug. If you cannot reproduce, you cannot prove a fix.

2 - Reduce the surface area
Smallest failing case

Strip the problem down. Remove features. Remove data. Remove async. Keep deleting until the bug disappears - then add the last thing back.

3 - Make a hypothesis
Write it in one line

"I think X happens because Y". If you cannot write it, you do not have a hypothesis - you have vibes.

4 - Add one instrument
Logs - metrics - breakpoints

Use logs like a microscope. Place them near boundaries - input, output, network, state transitions, and errors.

// Example log pattern
console.log("[auth] token present", Boolean(token));
console.log("[api] status", res.status, "timeMs", elapsedMs);
console.log("[ui] state", { loading, error, items: items.length });
5 - Run a controlled test
Change exactly one thing

Toggle one variable. Compare before and after. That is how you build confidence instead of guessing.

6 - Lock the fix
Prevent regressions

Add a small test or a guard. At minimum, add a comment near the fix stating what it prevents. Future you will thank present you.

Checklist you can reuse

  • Can I reproduce it in under 30 seconds
  • Did I reduce to the smallest failing example
  • Did I write one hypothesis sentence
  • Did I change only one thing
  • Did I confirm the fix with the original repro steps
  • Did I add a guard to prevent the same bug