๐— ๐˜† ๐—–๐—ฟ๐—ผ๐—ป ๐—๐—ผ๐—ฏ ๐—™๐—ฎ๐—ถ๐—น๐—ฒ๐—ฑ ๐—ฆ๐—ถ๐—น๐—ฒ๐—ป๐˜๐—น๐˜† ๐—ผ๐—ป ๐—–๐—น๐—ผ๐˜‚๐—ฑ๐—ณ๐—น๐—ฎ๐—ฟ๐—ฒ

The build passed. The deploy was green. But data stopped updating. No alerts. No crashes. I found out three days later.

I used a Cloudflare Worker. It pulled data from an API and sent it to Postgres. It worked for weeks. Then it stopped.

The logs showed one error. Too many subrequests by single Worker invocation.

A subrequest is any outbound fetch. Cloudflare's free plan allows 50 per invocation. Once you hit 50, every fetch fails.

I spent an hour tuning batch sizes. I moved from 25 to 15 items. Then to 10. It still failed.

The batching was not the problem. A new metadata feature made one fetch per item. 100 items meant 100 subrequests. I hit the limit before database writes started.

I optimized the part looking expensive. The real cost was a quiet loop in a different file.

When you hit a limit, count the resource. Do not optimize what looks heavy.

Three ways to fix this:

I removed the unnecessary calls.

Two lessons:

The most dangerous loop is the one you do not notice.

Source: https://dev.to/gitgem/my-cron-job-was-silently-failing-on-cloudflare-the-bug-wasnt-where-i-looked-31ko