PRACTITIONERCHAPTER 08

Debugging a problem you have never seen

Make the failure happen on demand, find what the failing cases share, test one hypothesis at a time and write each result down, and decide whether to stop the damage before you know the cause

45 MINSOFTWARE ENGINEERUPDATED 2026-11-21
PREDICT

A checkout error has hit some customers since Tuesday's release. The release has 14 commits, the service is new to you, and the failures look random. What is the most reliable first move?

Most bugs you meet in your first jobs are in code you did not write, in a system you have not mapped, reported by someone who cannot say exactly what they did. Writing the fix is usually the small part. The larger part is finding the problem when you do not already know where it is, in a way you can explain, repeat and hand over. People who are good at this do not guess better. They run a small, disciplined loop and keep a record.

The model: a bug is a question, and you answer it with experiments

A bug report is a symptom. The cause sits somewhere behind it, and between the two is a gap that only experiments close. Several books describe this loop. Andreas Zeller’s Why Programs Fail breaks debugging into seven steps whose initials spell TRAFFIC: track the problem, reproduce the failure, automate and simplify the test case, find possible infection origins, focus on the most likely, isolate the infection chain, and correct the defect. David Agans’ Debugging gives nine rules, among them Make It Fail, Divide and Conquer, Change One Thing at a Time and Keep an Audit Trail. Google’s SRE book treats troubleshooting as forming hypotheses and testing them.

Put together, the loop has five steps:

  1. Observe. What exactly failed, for whom, how often, since when, and what changed immediately before?
  2. Hypothesise. One specific, checkable claim about the cause: “the retry arrives while the first attempt is still running”, not “something is wrong with retries”.
  3. Predict. Write down what you will see if the claim is true and what you will see if it is false, before you look. If you skip this, every result will seem to agree with you.
  4. Test. The cheapest experiment that tells the two predictions apart. Change one thing or read one thing, not both.
  5. Record. Write the result and a verdict: supported, rejected or unclear. Then choose the next hypothesis from what you now know.

The record is not paperwork. It shows when you are testing the same idea twice, and lets a colleague take over at five o’clock without starting again.

Make it fail, then make it small

You cannot be sure you fixed something you never saw break. Agans’ second rule, after Understand the System, is Make It Fail: a failure you can trigger on demand lets you test a hypothesis in seconds instead of waiting for the next customer to hit it.

If it fails every time, capture the exact input and run it in the simplest place you can: your machine, a test, a staging copy. If it fails sometimes, do not try to reproduce it blindly. Gather a set of failing cases and a set of passing ones, and build a table with one column for every property you can read off a request: tier, amount, device, app version, time of day, region, path through the code. Then look for the columns where the failing cases agree with each other and the passing ones do not. A property shared by every failing case is a lead only if the passing cases mostly lack it, so look as hard at them as at the failures.

Shrink the input. Once you can make it fail, remove things until it stops failing, then put the last one back. A failing request with forty fields probably has one field that matters. Zeller and Hildebrandt call the systematic version delta debugging: remove part of the input, starting with half, test, and keep whatever still fails.

Shrink the history. If the bug appeared with a release, the cause is in the range of changes between the last good state and the first bad one. The command git bisect searches that range for you. You mark one commit good and one bad, it checks out the middle, you run your test and answer good or bad, and it halves the range again. A range of 200 commits needs at most eight tests, because 2 to the power of 8 is 256. It needs a test that gives the same answer every time; a flaky one sends the search down the wrong half and you will not know. With git bisect run and a script, the whole search runs unattended.

“What changed” is wider than code. Configuration, feature flags, the data in a table, a dependency version, a certificate, the traffic mix, the clock and the calendar all change a system. Agans’ rule Check the Plug is about this: before you build a theory, check that the thing is switched on, pointed at the right place and running the version you think it is.

Learning an unfamiliar system while you debug it

You do not need to understand the whole service to find one bug, only to follow one case through it.

Follow the data, not the diagram. Take a single failing case and trace it from input to output: where it enters, what reads it, what changes it, where it is stored. This is the same technique as the one-page map in the first ninety days, with a sharper question. Where the company has tracing, take the trace of a failing request and read what it touched; Debugging with traces shows how to get from a symptom to the one request that matters. Where it has structured logs with a request id on every line, as in Structured logging done properly, filter on the id of a failing request and read the whole story in order. Where it has neither, add one log line at each boundary that prints the value passing through.

Find where the value first goes wrong. This is Agans’ Divide and Conquer applied to a path instead of a range of commits. Check the value halfway along. If it is already wrong there, the cause is upstream; if it is still right, the cause is downstream. A path of sixteen steps takes four checks, not sixteen.

Read the history of the code you are in. git blame shows who last changed each line, and git log -S followed by a string finds the commits that added or removed it. The pull request behind a strange line often explains it.

Trust nobody and nothing. Julia Evans’ debugging manifesto, in the reading, names this attitude: your assumptions about the system, the library, the logs and your own earlier tests are all claims you can check. When a result contradicts your hypothesis, believe the result. When you cannot, test the test on a case where you already know the answer.

Ask a person, with a good question. The author may have left the company or moved teams. If someone owns the code now, or wrote it, ask: what you saw, what you have ruled out, and one specific question such as “does anything other than this handler write to this column?” The shape of a good question is the shape of a good bug report, covered in Bug reports that get fixed.

Hypothesis, test, result: the debugging log

The log is a table you keep as you go, in a file, a ticket or on paper.

Column What goes in it The usual mistake
Hypothesis One claim about the cause that a test could disprove “Probably a race condition”, which no test can reject
If true, I will see; if false Both predictions, written before the test Writing the prediction after looking
Test One read or one change, and where you ran it Changing two things at once, so a fix cannot be credited
Result What you saw, with the numbers Summarising as “looks fine”
Verdict Supported, rejected or unclear Leaving a rejected idea out because it was a waste of time

Three habits make the log work. Number the rows and write the time, so you can see where an hour went. Keep rejected hypotheses. A negative result narrows the search and tells the next reader what not to test. Keep a second list for things you notice that are not the bug: a misleading log line, a missing index, a wrong comment. Leave them alone. Fixing them now changes the system you are trying to understand, which breaks the one-change rule.

When a hypothesis is supported, the work is not over. Ask whether it explains the pattern you found at the start: the failing cases and only the failing cases. A cause that would also break the passing cases is not the cause, or not the whole of it. Often there are two parts: a trigger, the condition that sets the problem off, and a defect, the flaw that turns the trigger into damage. Fixing only the trigger leaves the defect waiting for the next one.

When you are stuck

Being stuck is normal in this work, and it passes. Do not stay stuck silently.

Set a limit. A rule of thumb, not a measured figure: if an hour passes and your log has eliminated nothing, change how you search. Return to the table of failing and passing cases and add columns, or check you have the right symptom.

Explain it to someone. Describing the problem aloud, to a colleague or a rubber duck, makes you state your assumptions, and one of them often sounds wrong as you say it. Agans’ rule Get a Fresh View is the same idea with a real person, who will ask the question you stopped asking.

Look at the size of the error. The size of a wrong number is evidence. Take a split bill where the shares come to ₦1 more than the total. If every share were rounded to the nearest kobo, each would be wrong by at most half a kobo, so you would need about 200 shares to reach ₦1, which is 100 kobo. A three-way split cannot get there by rounding; Residual cent shows the one-kobo gap it does leave. The gap points elsewhere: naira and kobo mixed up, a share dropped or counted twice, or a loop that ran one time too many or too few. Money in floating point covers the other family of causes.

Stop the damage, or find the cause?

While you debug, the bug keeps working. Every hour of a money bug is an hour in which customers are charged, or paid, a wrong amount. So alongside the investigation you are making a second decision: what to do now about the harm. The two decisions are separate. You can stop the damage without knowing the cause, and you can know the cause for an hour before the fix is safe to release.

Response What it does What it costs Right when
Roll back the release Returns to the last version known to behave Takes the whole release with it, including fixes you want; may be slow; unsafe if the release changed data in a one-way migration Several changes are suspect, or nothing smaller is available
Roll forward a guard Adds a check that makes the bad outcome impossible, or visible New code written under pressure; the feature may fail with an error instead You can state the rule that must hold, and a rollback is costly
Switch the feature off with its flag Stops the harm in the feature that is misbehaving, in minutes The feature is unavailable to everyone A flag covers the new path and the rest of the release is fine
Keep investigating Nothing changes for customers Each hour has a cost in wrong results The harm is small, reversible and tracked, and you have a strong lead

Choose by harm per hour, not by how well you understand the cause. Ask four questions: who is being hurt and how fast, can it be undone later, how long does each response take, and what else does it take with it. Then take the response with the smallest effect on everyone else that stops the harm. Wrong money is usually worse than a missing feature, which is why a flag is a good thing to build before you need it. Progressive delivery covers flags and staged rollouts, and Incident management covers what to do if the problem grows into an incident that needs a commander and a channel.

Two rules go with it. Say it aloud. Tell your lead and support what you switched off and why, in a sentence, before you carry on. Put a limit on any further investigation if you choose it: “until 11:00, then I switch it off”, written where your lead can see it. A mitigation closes the exposure, not the bug. Agans’ last rule, If You Didn’t Fix It, It Ain’t Fixed, is the reminder.

Fixing it properly

A good fix has four parts.

It explains the pattern. You can say how the cause produces exactly the failing cases and not the passing ones. If you cannot, you have found something wrong, not the thing.

It fixes the cause, not the symptom. A guard that rejects a bad total hides the bug and leaves the damage you have not yet found. Use a guard as a mitigation and then fix the defect behind it. Where a retry or a duplicate is involved, Idempotency and Webhook delivery describe the usual causes and fixes.

It has a regression test that fails before the change and passes after it. Run the test against the broken code first, to see it fail. A test you have never watched fail may not test what you think. Testing your own work covers how to plan tests for a change.

It repairs the damage. Wrong amounts already written need an owner: support to tell the customers, finance to correct the ledger, you to write the query that finds every affected row. Do not end the ticket at the code.

Describe the fix in a pull request a reviewer can act on, as in Pull requests that get merged, and put the cause in the description. Then write the incident up in a few lines: what failed, what the cause was, why it was not caught, and what changes. A blameless format keeps the lesson and drops the blame; Incidents and postmortems shows one. This is what engineering philosophies means by owning what you run.

Where practitioners disagree

Debugger or print statements. A debugger lets you stop a program and inspect it, and suits code you can run on your machine. Logs and traces suit production, timing and programs with many threads, where stopping one changes what happens. Use whichever answers your question fastest.

Roll back first, or understand first. Many operations teams roll back first and investigate afterwards, because a known state is worth more than a theory. Others point out that a rollback is not free: it removes good changes too, and a release that has already migrated data may be unsafe to reverse. This chapter’s position is to mitigate first, with the smallest response that stops the harm, which is sometimes a rollback and often is not.

Think or look. Agans’ rule is Quit Thinking and Look: do not theorise past the evidence, go and see what the system does. Experienced engineers still reason from the design to choose the next experiment. Use reasoning to choose the test, and the test to reach the conclusion.

Use an AI assistant or not. A model can read a stack trace, suggest causes and write a reproduction script, quickly. Treat what it says as hypotheses to enter in your log and test, not as findings. Working with AI coding agents covers what to verify before you trust its output.

Day to day

Debugging is spread through the week. The rhythm that works:

Each morning, ten minutes. Read the overnight errors and alerts for what you own, and the new tickets. Note anything odd even if you do not act. A bug you see on day one is cheaper than the same bug on day five.

When a bug lands, the first fifteen minutes. Answer four questions in writing: can I make it fail, how many cases, since when, what changed. Open the log and write the first row. If the answer to “how many” is growing, decide about the damage before you start the investigation.

Protect a block of time. A serious bug needs two or three unbroken hours, not twelve interrupted fifteen-minute slots; A software engineer’s week covers how to protect them.

Every hour on a long bug, a checkpoint. Read your own log. Is the next test the cheapest one? Has anything been eliminated? If the time limit you set has passed, tell your lead, with the log.

Pair for twenty minutes on any bug older than a day (a rule of thumb). Walk the other person through the log; their questions are the point.

End of the day, a handover note. Three lines: what is supported, what is rejected, what you would test next. Whoever picks it up, including you tomorrow, starts from the log.

Weekly, a thirty-minute bug triage with the product owner. Severity is how bad a failure is; priority is how soon it is fixed, and the product owner usually makes that call.

After a fix, twenty minutes. Write the regression test, the short write-up and the list of things you noticed. For anything that touched customers’ money, review it with the people affected within a few days.

BY ORG SIZE
STARTUPunder 30 people

There is often no staging data worth the name, so production is the only place the bug reproduces, and the person who wrote the code is one message away or is you. Debug in production carefully: read before you write, run read-only queries, and keep your log in the ticket so a founder can follow it. The danger is fixing at speed with no record and no test, so the same bug returns in three weeks. Spend the extra ten minutes on one regression test and the write-up. At this size they are the only memory the company has.

SCALE-UP30 to 300

Bugs now cross team lines: the symptom is in your service and the cause is in a neighbour’s. Instrumentation is uneven, so you will often have a trace on one side of a boundary and nothing on the other. The skill is to write the log and the bug report so that another team can act without you in the room, and to know whom to ask. Feature flags exist for some features and not others, so find out which before the day you need one. Time zones start to matter when the owner is asleep.

ENTERPRISE300 and up

There is usually a mature toolset, with tracing, a service catalogue, a ticketing process and an incident procedure, and the difficulty is process and access. Reading production data may need an approved request, customer data in logs is governed, and a rollback may need a change ticket or an approval. Learn the emergency route before you need it, and know what you may look at without asking. The log matters more here, because a bug may pass through three teams and a review board, and the people at the end will not remember what you tested.

ARTEFACT Keep a debugging log ~45 MIN
YOU PRODUCEDebugging log: hypothesis, test, result

Template

# Debugging log: <the symptom in one line>
Started · Owner · Last updated

## Symptom and impact
What failed, for whom, how many, since when, what changed immediately before:

## What the failing cases share
| Property | Failing (n=) | Passing (n=) |
|---|---|---|

## Log
| # | Time | Hypothesis | If true I see / if false I see | Test (one read or one change) | Result | Verdict |
|---|---|---|---|---|---|---|

## Decision about the damage (separate from the cause)
Response chosen · what it costs · what it leaves running · who was told · review time

## Cause
Trigger and defect, in two sentences; how it reproduces on demand; why it hits the failing cases and not the passing ones

## Fix, regression test and repair
Fix · the test that fails before and passes after · who repairs wrong data and how

## Noticed, not touched
WORKED EXAMPLE

Nakato is a mid-level engineer on Owoleaf’s Top-ups team (Owoleaf at 200 people, 44 engineers in six teams). On Monday at 08:30 finance’s morning reconciliation shows nine card top-ups credited twice, about ₦184,500 in all. The top-up handler was written by Nerys, who has moved to another team but answers within the hour. Nakato has never opened it. All figures are illustrative.

Symptom and impact. 9 of about 2,300 top-ups (0.4%) since Friday 14:00’s release, about three a day; none in the three weeks before. Each has two credit rows, 10.1 to 10.6 seconds apart. Failing cases share: a retry by the card processor, whose documentation gives a 10-second timeout. Ordinary top-ups show one delivery.

# Hypothesis If true / if false Result Verdict
1 The processor sent two different events per charge, so our dedupe was right Two event ids per charge / one id, two delivery attempts One event id each; first attempt timed out at 10 s, second got 200 Rejected: the duplicate is ours
2 Our dedupe misses a retry that arrives while the first attempt is still running First attempts last over 10 s, ordinary ones under 2 s / similar times Nine first attempts 10.4 to 14.8 s; fifty ordinary ones 0.4 to 1.9 s Supported
3 The slow part is the confirmation message sent inside the handler Time passes between “credited” and “message sent” / elsewhere 9.8 to 14.4 s between those log lines in all nine Supported: a trigger, not the defect
4 Friday’s change moved the event-id record from first step to last The diff shows it, and sending one event twice at once credits once on the old version and twice on the new Both held, reproduced locally in one minute; Nerys confirms the first-step record was deliberate Confirmed

Decision about the damage. Fixed forward the same day instead of rolling back: harm was about three double credits a day, and the release carried a fix for the statement screen. Until the fix shipped, doubles carried on and finance reversed them by hand; the lead and support were told at 09:10. Cause. Trigger: a slow message call pushes the attempt past the processor’s timeout. Defect: the event id is recorded last, so the retry passes the check. Ordinary top-ups never reach 10 seconds, which is why 99.6% were fine (rows 2 to 4). Fix. Record the event id in the same transaction as the credit, first, under a unique key; send the message after commit from a queue. Regression test: two concurrent deliveries of one event produce one credit, and it fails on Friday’s code. Finance reverses the nine credits; support tells the customers. Noticed, not touched: two other handlers record their event id last.

Now you

You are an engineer at Owoleaf (200 people). It is Wednesday 08:30 and you have never opened the nightly limit-reset job. Daily send limits are ₦30,000 on tier 1 and ₦200,000 on tier 2, and they reset at midnight, Nigeria time (WAT, UTC+1, no daylight saving). Four customers (rows 1 to 4) say they were refused with “daily limit reached” soon after midnight although they had sent nothing yet on Wednesday. Support pulled four more cases for comparison. Tuesday’s release moved the reset job to a new job runner. There were no such complaints on Monday night.

# Tier Sent Tuesday Tried Wednesday (WAT) Amount Result
1 1 ₦29,500 00:12 ₦1,000 Refused
2 2 ₦195,000 00:41 ₦10,000 Refused
3 1 ₦30,000 00:58 ₦2,000 Refused
4 2 ₦200,000 00:47 ₦5,000 Refused
5 1 ₦30,000 01:12 ₦2,000 Accepted
6 2 ₦200,000 01:30 ₦50,000 Accepted
7 1 ₦5,000 00:30 ₦10,000 Accepted
8 2 ₦180,000 00:20 ₦15,000 Accepted

The runner’s log for Tuesday night reads limit-reset started 00:00:03Z, finished 00:06:41Z. The old host’s log for Monday night reads started 00:00:02, finished 00:05:58, with no zone. The runner’s settings show a time zone field set to default. A colleague on another team says the new runner is slow. Write the debugging log: what the cases share, at least three hypotheses with predictions, the result of each from the evidence above, the cause, and what you do about the damage.

Self-check

DECIDE

You are an engineer at Owoleaf (200 people). Tuesday's release changed how split-bill shares are calculated. It is Wednesday 09:30. Since then about 2% of split-bill requests, roughly 6 an hour in the working day (illustrative), return shares that add up to ₦1 more or less than the bill, and nine customers have written in. You suspect the new share code but have not confirmed it. Split-bill sits behind a feature flag that takes effect in about a minute, and the team's runbook lets any engineer switch it off. A full rollback takes about 40 minutes and would also remove a login fix from the same release, which stopped about 3 in 100 Android sign-ins from failing. Your lead is in a meeting until 11:00. What do you do?

READING
  1. BOOK
    Why Programs Fail: A Guide to Systematic Debugging Andreas Zeller, 2009

    A systematic method for debugging, from tracking and reproducing the problem to isolating and correcting it. Read it for the habit of turning a vague failure into a small, repeatable one before you theorise. Read: Morgan Kaufmann, second edition; the TRAFFIC steps are introduced in the opening chapters.

  2. BOOK
    Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems David J. Agans, 2002

    The nine rules this chapter draws on, each with its own chapter and stories from hardware and software. Short enough to read in an evening and tool-agnostic. Read: AMACOM; one chapter per rule, including Make It Fail and Divide and Conquer.

  3. BOOK
    Site Reliability Engineering, chapter 12: Effective Troubleshooting Beyer, Jones, Petoff and Murphy (eds.), 2016

    Google's SREs on troubleshooting production systems as forming and testing hypotheses. Read it for how the approach holds up when the system is large and several people are looking at once. Read: Part III, Practices; chapter 12.

  4. POST
    A debugging manifesto Julia Evans, 2022

    A short statement of the attitude that helps: inspect rather than squash, trust nobody and nothing, being stuck is temporary, and ask for help. Useful on the day a bug has beaten you for three hours.

  5. DOC
    git bisect Git documentation

    The reference for searching a range of commits for the one that introduced a bug, including git bisect run for automating the search with a script. Learn it before the day you need to find a change among two hundred.

All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.
NEXT: Testing your own work →