Back to Coding

How Do You Debug an Intermittent Failure?

How Do You Debug an Intermittent Failure?
AI Tutorials Team 10 April 2026

It works most of the time. Nothing is more frustrating and nothing has a narrower set of causes, which means categorising it is genuinely productive where general investigation is not.

What are the categories?

  • Timing. Two things whose order is not guaranteed.
  • Specific data. One record with something unusual.
  • Resources. Memory, connections or quota under load.
  • External dependency. A service that fails occasionally.
  • Accumulated state. Something that degrades over time.

How do you distinguish them?

By the pattern. Failures under load suggest resources. Failures on particular records suggest data. Failures at a consistent time suggest something scheduled. Failures that increase the longer the process runs suggest accumulation.

The pattern is therefore the thing to establish before investigating anything.

How do you rule out data quickly?

By running the operation over everything and catching failures. If eleven specific records fail every time, this is not intermittent at all: it is a reproducible bug that appeared random because the input varied.

That check takes ten minutes and resolves a substantial share of these.

What does a timing problem look like?

Failures that change with load, that appear on faster or slower machines, or that disappear when you add logging. That last one is the classic signal, since logging changes timing.

This fails intermittently. Here is the code and here is when it fails. Is there anything here where two operations could run in an unguaranteed order, or where something could be read before it is written?

Why is AI weak on timing?

Because the bug is not in the text. Each part is correct in isolation and the failure comes from interleaving, which is not visible in the code being read. Treat suggestions here as prompts to investigate rather than as diagnoses.

What does resource exhaustion look like?

Failures under load, recovery after a restart, and gradual degradation. Connections not being released is the most common instance in small applications, and it produces exactly this pattern.

What should you add?

Logging that captures the conditions rather than the failure. A request identifier, the values involved, timing, and whatever the suspected categories would distinguish. Then wait for it to happen.

Waiting deliberately is the correct strategy here, which it rarely is elsewhere.

What about retries?

Reasonable for external dependencies and a concealment for anything else. A retry that hides a race condition means the bug remains and now produces occasional duplicate work instead of occasional failures.

How long should you watch before concluding?

Long enough to see it several times, which depends entirely on frequency. Something happening daily gives you evidence within a week; something happening monthly does not, and declaring it fixed after one clean period is a guess.

What helps is recording occurrences rather than relying on impressions. A count of failures per day, before and after a change, is the only way to tell whether an intermittent problem improved, and people are reliably poor at judging that from memory.

What is the honest position?

Some of these cost more to find than they cost to tolerate. Something failing rarely, with a small consequence and a retry that resolves it, may be reasonable to log and monitor rather than to chase, and deciding that deliberately is better than an open-ended investigation.