600 queries, a 5-second limit

A recent bug: 600 queries against a 5-second limit.

Every contact in Cold Leads has a temperature built from signals: a form fill, a reply, a pricing question. A background job recalculates the contacts that changed, 200 at a time, in one database transaction.

Per contact it ran three queries: delete the old signals, insert the new ones, update the score. 200 contacts ≈ 600 queries.

After a bulk import that took 5.2 seconds. Prisma's limit for that kind of transaction is 5. The whole batch rolled back, and every run retried it and failed again.

The fix wasn't a bigger timeout:

  • one delete for the whole batch
  • one insert for all the signals
  • one update per distinct score (scores are whole degrees, so there are only a few dozen possible values)

600 queries became a handful.

Rule I keep relearning: count the round trips before you tune the timeout.

Build on Cold Leads

REST API, the Node SDK @coldleads/sdk and the MCP server @coldleads/mcp-server. Plans from $19 a month; new accounts get 5 days free (card required).