# The bug that only reproduces in production is almost always the data, not the code — retained record

> Retained reddit record from reddit:developersIndia.

Canonical: https://highsignal.app/data/records/1166437852c2af78

[← sources](https://highsignal.app/data)


source: [reddit](https://highsignal.app/data/reddit) (reddit:developersIndia)  published 2026-11-03 03:34 ingested 2026-11-04 02:37

[original source ↗](https://www.reddit.com/r/developersIndia/comments/1xmiez7/the_bug_that_only_reproduces_in_production_is/)

## retained text



```
There's a category of bug that eats entire sprints and has nothing to do with your code being wrong. It works locally, it works in staging, it fails for one customer in production, and the failure is a timeout or a wrong number rather than a stack trace.

Nearly all of these come down to one difference: staging has two hundred rows and production has two million. The code is the same. The shape of the data is not.

Four versions of it, in the order I'd check them.

**The N+1 that stays invisible until the table grows.** A loop that queries once per row costs the same per iteration whether the table has 50 rows or 50,000. At 50 rows it's 50 quick queries and nobody notices. At 50,000 it's 50,000 round trips, and it surfaces as "the dashboard got slow" months later, usually right after a launch. The query count, not the query time, is the number to watch, and most ORMs will log it for you if you switch that on in staging.

**An index that exists in one environment and not the other.** Migrations ran in a different order, someone added an index by hand on the dev box, and the query plan you tuned against is not the plan production is using. Run `EXPLAIN` in the environment that is slow, not the one that is fast.

**Sorting or filtering on a column that's mostly one value.** Works beautifully on test data where every value differs. Falls over when 90% of the rows share the same value, because the index stops being useful and you get a sort of the whole table.

**Uniqueness and length assumptions that only real data breaks.** A `varchar(50)` name field, a phone number with a country code in it, an emoji, a duplicate that "can't happen". Test data written by engineers is uniformly well-formed. Customer data is not, and that isn't a bug in the customer.

The fix that actually works isn't more test coverage, it's seeding staging from a sample of production with the sensitive fields scrambled, at a size where the bad behaviour shows up. Ten thousand rows, not fifty. If your staging database fits inside a single INSERT statement you wrote, you're not testing the thing that breaks.

The cheap version, for when you can't get production data at all: before shipping a query, ask what it does when the table is a thousand times bigger than it is now. Not "will it be fast", but "does it do the same number of things per row, or more".

For people running this at real size: what's the difference between staging and production you stopped trying to fix and just learned to work around?
```



document fetched 2026-11-04 00:24 · canonical https://reddit.com/r/developersIndia/comments/1xmiez7/the_bug_that_only_reproduces_in_production_is
