← Statpro dev log

A 60-second timeout that worked until production

#data#infra#web

A dial with a short thick amber arc that stops at a marker while a dotted track continues around the rest of the semicircle.

Every test passed, my pre-launch checklist of acceptance checks was signed off, and the production backfill timed out at 60 seconds. The migration logic was fine. Its time budget had been sized for a different database.

The change merged two feeds, Trending and public News, on Statpro, a sports stats site: 85 files, 24,000 insertions, and a database migration that gives every news item its own permanent public URL. A backfill is a migration step that fills in that new data for rows that already exist.

A budget copied from the test fixture

The migration opened with a statement timeout, which is a sensible guard. The number was the problem, because it came from the fixture-sized test budget:

SET LOCAL statement_timeout = '60s';
-- the route backfill fires a row-level minting trigger
-- for every currently public item

The test database holds a few hundred rows. Production holds a 24-month corpus across MLB, NBA and NFL, and the backfill fires that trigger once per public item. The trigger is the database hook that creates each item's URL. Sixty seconds was generous in one place and impossible in the other.

Fifteen minutes, pinned by a test

I raised the budget to 15 minutes and added a test that reads the migration's SQL, so the old value can't drift back in:

assert.match(sql, /SET LOCAL statement_timeout = '15min'/u);
assert.doesNotMatch(sql, /SET LOCAL statement_timeout = '60s'/u);

The timeout is still bounded on purpose. A runaway migration is worse than a slow one, so the limit stays.

Size limits for the data they'll meet

A passing test proves the logic. It says nothing about how long that logic takes on real volume. Any limit that scales with row count needs to be set against production's size, and a few hundred fixture rows can't tell you what that is.

This is the build log for Statpro (statpro.io) · All entries · Weekly essays